CQL-запрос ВНУТРИ с использованием инструментов java - PullRequest
0 голосов
/ 27 мая 2020

Мне нужно найти все рестораны в 1000 МЕТРАХ от определенного места. Мой уровень restautrent cite: restaurents Координаты местоположения - 76.10, 10.51

Я использую код ниже

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
String getCapabilities = http://localhost:8080/geoserver/ows?service=wfs&version=1.1.0&request=GetCapabilities";
Map<String, Serializable> connectionParameters = new HashMap<>();
connectionParameters.put(WFSDataStoreFactory.URL.key, getCapabilities);
WFSDataStoreFactory dsf = new WFSDataStoreFactory();
WFSDataStore dataStore = dsf.createDataStore(connectionParameters);
String types[] = dataStore.getTypeNames();

String name = "cite:restaurents";
Point point = geometryFactory.createPoint(new Coordinate(76.10, 10.51));
// Filter filter = CQL.toFilter(String.format("DWITHIN(%s, POINT(76.10
// 10.51),1000, meters)", "geom"));
FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2();
Filter filter = filterFactory.dwithin(filterFactory.property("the_geom"), filterFactory.literal(point),
        1000, "meters");

SimpleFeatureSource source = dataStore.getFeatureSource(name);
source.getBounds();

SimpleFeatureCollection fc = source.getFeatures(filter);

SimpleFeatureIterator itr = fc.features();
while (itr.hasNext()) {
    SimpleFeature sf = itr.next();

    System.out.println(sf);
}

ниже исключения

[[java.lang.RuntimeException: Parsing failed for Distance: java.lang.NullPointerException
Parsing failed for Distance: java.lang.NullPointerException]]
at org.geotools.data.wfs.v1_1_0.parsers.ExceptionReportParser.parse(ExceptionReportParser.java:103) ~[gt-wfs-15.2.jar:na]
at org.geotools.data.wfs.protocol.wfs.WFSExtensions.process(WFSExtensions.java:86) ~[gt-wfs-15.2.jar:na]
at org.geotools.data.wfs.v1_1_0.WFS_1_1_0_DataStore.getFeatureReader(WFS_1_1_0_DataStore.java:449) ~[gt-wfs-15.2.jar:na]
at org.geotools.data.wfs.v1_1_0.WFSFeatureCollection.reader(WFSFeatureCollection.java:172) ~[gt-wfs-15.2.jar:na]
at org.geotools.data.store.DataFeatureCollection.openIterator(DataFeatureCollection.java:230) ~[gt-main-15.2.jar:na]
at org.geotools.data.store.DataFeatureCollection.iterator(DataFeatureCollection.java:198) ~[gt-main-15.2.jar:na]
at org.geotools.data.store.DataFeatureCollection.features(DataFeatureCollection.java:187) ~[gt-main-15.2.jar:na]
at com.hamdhan.geotooltest.controller.LayerController.TestGeoToolsRestAPI(LayerController.java:85) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_252]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_252]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_252]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_252]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) ~[spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879) ~[spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793) ~[spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]

пожалуйста, найдите ниже зависимости https://maven.apache.org/xsd/maven-4.0.0.xsd "> 4.0.0 org.springframework.boot spring-boot-starter-parent 2.3.0.RELEASE com.hamdhan geotooltest 0.0.1-SNAPSHOT war geotooltest Инструмент Geo тестирование

<properties>
    <java.version>1.8</java.version>
    <geotools.version>15.2</geotools.version>
    <geotools-swing.version>15.2</geotools-swing.version>
    <geotools-shapefile.version>15.2</geotools-shapefile.version>
</properties>

<dependencies>
     <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-shapefile</artifactId>
        <version>${geotools-shapefile.version}</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-wfs</artifactId>
        <version>15.2</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-cql</artifactId>
        <version>15.2</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>
 <repositories>
   <!--  <repository>
        <id>osgeo</id>
        <name>Open Source Geospatial Foundation Repository</name>
        <url>http://download.osgeo.org/webdav/geotools/</url>
    </repository> -->
    <repository>
    <id>osgeo</id>
    <name>OSGeo Release Repository</name>
    <url>https://repo.osgeo.org/repository/release/</url>
    <snapshots><enabled>false</enabled></snapshots>
    <releases><enabled>true</enabled></releases>
  </repository>
</repositories>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

1 Ответ

0 голосов
/ 27 мая 2020

Вы можете настроить это как фильтр CQL или использовать FilterFactory, но правила будут разными в зависимости от того, что вы выберете.

Вы можете использовать CQL (это быстро и легко):

Filter filter = CQL.toFilter("dwithin(\"the_geom\","+point+", 1000, meters)");
...