Last active
May 25, 2017 19:28
-
-
Save fernandor777/f786713abf276c614f09ab4dd04e834b to your computer and use it in GitHub Desktop.
Geotools WFS query with CQL for get feature Bounding Box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Bbox testWFS(){ | |
String getCapabilities = "http://app.orbis/geoserver/ows?service=wfs&version=1.1.0&request=GetCapabilities"; | |
Map connectionParameters = new HashMap(); | |
connectionParameters.put("WFSDataStoreFactory:GET_CAPABILITIES_URL", getCapabilities); | |
WFSDataStoreFactory dsf = new WFSDataStoreFactory(); | |
try { | |
WFSDataStore dataStore = dsf.createDataStore(connectionParameters); | |
SimpleFeatureSource source = dataStore.getFeatureSource("catastro:geo_predio"); | |
// cod_catast = 04-027-048-16 | |
Filter flt = CQL.toFilter("cod_catast = '04-027-048-16' "); | |
SimpleFeatureCollection fc = source.getFeatures(flt); | |
if(!fc.isEmpty()){ | |
SimpleFeature sf = fc.features().next(); | |
BoundingBox boundResult = sf.getBounds(); | |
Bbox bbx = new Bbox(boundResult.getMinX(), boundResult.getMaxX(), boundResult.getMinY(), boundResult.getMaxY()); | |
return bbx; | |
} | |
// while(fc.features().hasNext()){ | |
// SimpleFeature sf = fc.features().next(); | |
// System.out.println(sf.getAttribute("myname")); | |
// } | |
} catch (IOException ex) { | |
Logger.getLogger(PruebasRest.class.getName()).log(Level.SEVERE, null, ex); | |
} catch (CQLException ex) { | |
Logger.getLogger(PruebasRest.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
return null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>gob.libertad</groupId> | |
<artifactId>geoapi-libertad</artifactId> | |
<version>1.0</version> | |
<packaging>war</packaging> | |
<name>geoapi-libertad</name> | |
<properties> | |
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<geotools.version>17.1</geotools.version> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>javax</groupId> | |
<artifactId>javaee-api</artifactId> | |
<version>7.0</version> | |
<scope>provided</scope> | |
</dependency> | |
<dependency> | |
<groupId>com.fmino.geo</groupId> | |
<artifactId>restdata</artifactId> | |
<version>1.0</version> | |
<scope>compile</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.geotools</groupId> | |
<artifactId>gt-main</artifactId> | |
<version>${geotools.version}</version> | |
<type>jar</type> | |
</dependency> | |
<dependency> | |
<groupId>org.geotools</groupId> | |
<artifactId>gt-opengis</artifactId> | |
<version>${geotools.version}</version> | |
<type>jar</type> | |
</dependency> | |
<dependency> | |
<groupId>org.geotools</groupId> | |
<artifactId>gt-api</artifactId> | |
<version>${geotools.version}</version> | |
<type>jar</type> | |
</dependency> | |
<dependency> | |
<groupId>org.geotools</groupId> | |
<artifactId>gt-data</artifactId> | |
<version>${geotools.version}</version> | |
<type>jar</type> | |
</dependency> | |
<dependency> | |
<groupId>org.geotools</groupId> | |
<artifactId>gt-wfs-ng</artifactId> | |
<version>${geotools.version}</version> | |
<type>jar</type> | |
</dependency> | |
<dependency> | |
<groupId>org.geotools</groupId> | |
<artifactId>gt-cql</artifactId> | |
<version>${geotools.version}</version> | |
<type>jar</type> | |
</dependency> | |
<dependency> | |
<groupId>org.geotools</groupId> | |
<artifactId>gt-epsg-hsql</artifactId> | |
<version>${geotools.version}</version> | |
<type>jar</type> | |
</dependency> | |
</dependencies> | |
<repositories> | |
<repository> | |
<id>boundless</id> | |
<name>Boundless</name> | |
<url>http://repo.boundlessgeo.com/main/</url> | |
</repository> | |
<!-- <repository> | |
<id>osgeo</id> | |
<name>Open Source Geospatial Foundation Repository</name> | |
<url>http://download.osgeo.org/webdav/geotools/</url> | |
</repository> | |
<repository> Add the snapshot repository here | |
<snapshots> | |
<enabled>true</enabled> | |
</snapshots> | |
<id>opengeo</id> | |
<name>OpenGeo Maven Repository</name> | |
<url>http://repo.opengeo.org</url> | |
</repository>--> | |
</repositories> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<version>3.1</version> | |
<configuration> | |
<source>1.7</source> | |
<target>1.7</target> | |
<compilerArguments> | |
<endorseddirs>${endorsed.dir}</endorseddirs> | |
</compilerArguments> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-war-plugin</artifactId> | |
<version>2.3</version> | |
<configuration> | |
<failOnMissingWebXml>false</failOnMissingWebXml> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-dependency-plugin</artifactId> | |
<version>2.6</version> | |
<executions> | |
<execution> | |
<phase>validate</phase> | |
<goals> | |
<goal>copy</goal> | |
</goals> | |
<configuration> | |
<outputDirectory>${endorsed.dir}</outputDirectory> | |
<silent>true</silent> | |
<artifactItems> | |
<artifactItem> | |
<groupId>javax</groupId> | |
<artifactId>javaee-endorsed-api</artifactId> | |
<version>7.0</version> | |
<type>jar</type> | |
</artifactItem> | |
</artifactItems> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment