Re: [Geoserver-users] [EXTERNAL] - RE: WPS gs:Clip Topology Exception

2022-03-31 Thread Oscar Wu
Hi everyone,

After a few more trial and errors, I finally figured out the source of the 
Topology Exception. My source 
data<http://openmaps.gov.bc.ca/geo/pub/ows?service=WFS=2.0.0=GetFeature=WHSE_CADASTRE.PMBC_PARCEL_FABRIC_POLY_SVW=json=715319.3721917,1027297.643601,735025.9926936,1041407.195003>
 contains a mix of MultiPolygon and Polygon geometries. When they are put into 
a FeatureCollection to be consumed by the WPS, everything was converted to 
Polygons. This led to an issue with the Multipolygons. In green below is one of 
the Multipolygons that was converted to Polygon. Notice the line connecting the 
two parts, it was a side effect from the conversion because the last coordinate 
always needs to match with the first coordinate for a Polygon so the first 
coordinate was added in the end of the coordinate sequence by the conversion. 
This made the geometry invalid.

[cid:46bae7cc-87c3-4b26-b5d0-b8ef762c25f6]

The visualization really helped me understand the problem. To fix it, I broke 
the MultiPolygon into multiple Polygons and then put the polygon into the 
FeatureCollection. No further TopologyException was reported ever since.

Thanks everyone for reading my question and thank you Dominique for your 
suggestions.

Regards,

Oscar



From: Oscar Wu 
Sent: March 24, 2022 4:29 PM
To: Bessette-Halsema, Dominique E ; 
geoserver-users@lists.sourceforge.net 
Subject: Re: [Geoserver-users] [EXTERNAL] - RE: WPS gs:Clip Topology Exception

Hi Dominique,

Thanks again for the help.

I check the CRS of my clipping polygon using geometry.getSRID() it returned 0. 
Knowing this I added the SRID of 3005 using geometry.setSRID(3005) in my custom 
WPS to have it match with the other input. However, I'm still seeing the same 
Topology Exception.

I feel like this might not be related to coordinate systems though. I have 
other data sources that works fine with the same clipping geometry even without 
assigning the CRS.

One other thing I tried was to use the TopologyPreservingSimlifier and the 
DouglasPeuckerSimplifier. I thought the data source might contain complex 
polygons which lead to topology mismatch. Unfortunately, the same error was 
still here.

I'm wondering if you have more suggestions? Thanks!

Regards,

Oscar

From: Bessette-Halsema, Dominique E 
Sent: March 24, 2022 11:45 AM
To: Oscar Wu ; geoserver-users@lists.sourceforge.net 

Subject: RE: [EXTERNAL] - RE: WPS gs:Clip Topology Exception


There are several ways to set the CRS in the Geometry, but this probably wont 
fix your problem. I just worry that the code is setting your Geometry to the 
default EPSG and that’s why it cant figure it out.  Also there are some 
Geometry limits, like crossing the antemeridian.  If you are crossing the 
antemeridian you can try shifting your polygon from 180, -180 to 0, 360 or 
break it into 2 pieces.



You can do an EPSG check:  geometry.getSRID().



Example 1: create an Envelope and then create the Geometry

 Envelope impactEnvelope = new ReferencedEnvelope(newMinX, maxx, 
miny, maxy,

   CRS.decode("EPSG:4326"));

 Geometry myGeom = JTS.toGeometry(impactEnvelope).getEnvelope();;





example 2: use mathTransform

 MathTransform transform = CRS.findMathTransform(sourceCRS, 
targetCRS, false);

 Geometry targetGeometry = JTS.transform( myGeom, transform);



Hope this helps!



Dominique Bessette

Senior Software Engineer




From: Oscar Wu 
Sent: Thursday, March 24, 2022 11:23 AM
To: Bessette-Halsema, Dominique E ; 
geoserver-users@lists.sourceforge.net
Subject: Re: [EXTERNAL] - RE: WPS gs:Clip Topology Exception





 [External: Use caution with links & attachments]



Hi Dominique,



Thank you very much for the suggestion.



I tried to explicitly define the EPSG in the getFeature request by adding 
srsName=EPSG:3005 to the url. The clipping geometry has no place to add SRS as 
it is only a geometry not a feature. However, I have made sure the coordinates 
in the clipping geometry are also generated under EPSG:3005. That being said, 
it unfortunately did not solve the issue.



Is there anything else I can try?



Thanks!



Oscar



From: Bessette-Halsema, Dominique E 
mailto:dominique.besse...@gdit.com>>
Sent: March 24, 2022 9:30 AM
To: Oscar Wu mailto:oscar...@crmltd.ca>>; 
geoserver-users@lists.sourceforge.net<mailto:geoserver-users@lists.sourceforge.net>
 
mailto:geoserver-users@lists.sourceforge.net>>
Subject: [EXTERNAL] - RE: WPS gs:Clip Topology Exception



You may want to try specifying your EPSG in your Polygon and getFeature request



Dominique Bessette

Senior Software Engineer



From: Oscar Wu mailto:oscar...@crmltd.ca>>
Sent: Wednesday, March 23, 2022 1:02 PM
To: 
geoserver-users@lists.sourceforge.net<mailto:geoserver-users@lists.sourceforge.net>
S

Re: [Geoserver-users] [EXTERNAL] - RE: WPS gs:Clip Topology Exception

2022-03-24 Thread Oscar Wu
Hi Dominique,

Thanks again for the help.

I check the CRS of my clipping polygon using geometry.getSRID() it returned 0. 
Knowing this I added the SRID of 3005 using geometry.setSRID(3005) in my custom 
WPS to have it match with the other input. However, I'm still seeing the same 
Topology Exception.

I feel like this might not be related to coordinate systems though. I have 
other data sources that works fine with the same clipping geometry even without 
assigning the CRS.

One other thing I tried was to use the TopologyPreservingSimlifier and the 
DouglasPeuckerSimplifier. I thought the data source might contain complex 
polygons which lead to topology mismatch. Unfortunately, the same error was 
still here.

I'm wondering if you have more suggestions? Thanks!

Regards,

Oscar

From: Bessette-Halsema, Dominique E 
Sent: March 24, 2022 11:45 AM
To: Oscar Wu ; geoserver-users@lists.sourceforge.net 

Subject: RE: [EXTERNAL] - RE: WPS gs:Clip Topology Exception


There are several ways to set the CRS in the Geometry, but this probably wont 
fix your problem. I just worry that the code is setting your Geometry to the 
default EPSG and that’s why it cant figure it out.  Also there are some 
Geometry limits, like crossing the antemeridian.  If you are crossing the 
antemeridian you can try shifting your polygon from 180, -180 to 0, 360 or 
break it into 2 pieces.



You can do an EPSG check:  geometry.getSRID().



Example 1: create an Envelope and then create the Geometry

 Envelope impactEnvelope = new ReferencedEnvelope(newMinX, maxx, 
miny, maxy,

   CRS.decode("EPSG:4326"));

 Geometry myGeom = JTS.toGeometry(impactEnvelope).getEnvelope();;





example 2: use mathTransform

 MathTransform transform = CRS.findMathTransform(sourceCRS, 
targetCRS, false);

 Geometry targetGeometry = JTS.transform( myGeom, transform);



Hope this helps!



Dominique Bessette

Senior Software Engineer




From: Oscar Wu 
Sent: Thursday, March 24, 2022 11:23 AM
To: Bessette-Halsema, Dominique E ; 
geoserver-users@lists.sourceforge.net
Subject: Re: [EXTERNAL] - RE: WPS gs:Clip Topology Exception





 [External: Use caution with links & attachments]



Hi Dominique,



Thank you very much for the suggestion.



I tried to explicitly define the EPSG in the getFeature request by adding 
srsName=EPSG:3005 to the url. The clipping geometry has no place to add SRS as 
it is only a geometry not a feature. However, I have made sure the coordinates 
in the clipping geometry are also generated under EPSG:3005. That being said, 
it unfortunately did not solve the issue.



Is there anything else I can try?



Thanks!



Oscar



From: Bessette-Halsema, Dominique E 
mailto:dominique.besse...@gdit.com>>
Sent: March 24, 2022 9:30 AM
To: Oscar Wu mailto:oscar...@crmltd.ca>>; 
geoserver-users@lists.sourceforge.net
 
mailto:geoserver-users@lists.sourceforge.net>>
Subject: [EXTERNAL] - RE: WPS gs:Clip Topology Exception



You may want to try specifying your EPSG in your Polygon and getFeature request



Dominique Bessette

Senior Software Engineer



From: Oscar Wu mailto:oscar...@crmltd.ca>>
Sent: Wednesday, March 23, 2022 1:02 PM
To: 
geoserver-users@lists.sourceforge.net
Subject: [Geoserver-users] WPS gs:Clip Topology Exception





 [External: Use caution with links & attachments]



Hi everyone,



First time posting here, thank you for your understanding if I am not 
explaining my situation well.



I've been trying to use the built-in gs:Clip to extract some public layers 
based on a polygon defined by coordinates. The process seemed to work well with 
a couple of layers until I tried it with one particular layer.



Here's the xml in the POST request:

http://www.w3.org/2001/XMLSchema-instance"
 
xmlns="http://www.opengis.net/wps/1.0.0;
 
xmlns:wfs="http://www.opengis.net/wfs"
 
xmlns:wps="http://www.opengis.net/wps/1.0.0"
 
xmlns:ows="http://www.opengis.net/ows/1.1"
 

Re: [Geoserver-users] [EXTERNAL] - RE: WPS gs:Clip Topology Exception

2022-03-24 Thread Bessette-Halsema, Dominique E via Geoserver-users
There are several ways to set the CRS in the Geometry, but this probably wont 
fix your problem. I just worry that the code is setting your Geometry to the 
default EPSG and that's why it cant figure it out.  Also there are some 
Geometry limits, like crossing the antemeridian.  If you are crossing the 
antemeridian you can try shifting your polygon from 180, -180 to 0, 360 or 
break it into 2 pieces.

You can do an EPSG check:  geometry.getSRID().

Example 1: create an Envelope and then create the Geometry
 Envelope impactEnvelope = new ReferencedEnvelope(newMinX, maxx, 
miny, maxy,
   CRS.decode("EPSG:4326"));
 Geometry myGeom = JTS.toGeometry(impactEnvelope).getEnvelope();;


example 2: use mathTransform
 MathTransform transform = CRS.findMathTransform(sourceCRS, 
targetCRS, false);
 Geometry targetGeometry = JTS.transform( myGeom, transform);

Hope this helps!

Dominique Bessette
Senior Software Engineer


From: Oscar Wu 
Sent: Thursday, March 24, 2022 11:23 AM
To: Bessette-Halsema, Dominique E ; 
geoserver-users@lists.sourceforge.net
Subject: Re: [EXTERNAL] - RE: WPS gs:Clip Topology Exception


 [External: Use caution with links & attachments]

Hi Dominique,

Thank you very much for the suggestion.

I tried to explicitly define the EPSG in the getFeature request by adding 
srsName=EPSG:3005 to the url. The clipping geometry has no place to add SRS as 
it is only a geometry not a feature. However, I have made sure the coordinates 
in the clipping geometry are also generated under EPSG:3005. That being said, 
it unfortunately did not solve the issue.

Is there anything else I can try?

Thanks!

Oscar

From: Bessette-Halsema, Dominique E 
mailto:dominique.besse...@gdit.com>>
Sent: March 24, 2022 9:30 AM
To: Oscar Wu mailto:oscar...@crmltd.ca>>; 
geoserver-users@lists.sourceforge.net
 
mailto:geoserver-users@lists.sourceforge.net>>
Subject: [EXTERNAL] - RE: WPS gs:Clip Topology Exception


You may want to try specifying your EPSG in your Polygon and getFeature request



Dominique Bessette

Senior Software Engineer



From: Oscar Wu mailto:oscar...@crmltd.ca>>
Sent: Wednesday, March 23, 2022 1:02 PM
To: 
geoserver-users@lists.sourceforge.net
Subject: [Geoserver-users] WPS gs:Clip Topology Exception





 [External: Use caution with links & attachments]



Hi everyone,



First time posting here, thank you for your understanding if I am not 
explaining my situation well.



I've been trying to use the built-in gs:Clip to extract some public layers 
based on a polygon defined by coordinates. The process seemed to work well with 
a couple of layers until I tried it with one particular layer.



Here's the xml in the POST request:

http://www.w3.org/2001/XMLSchema-instance"
 
xmlns="http://www.opengis.net/wps/1.0.0;
 
xmlns:wfs="http://www.opengis.net/wfs"
 
xmlns:wps="http://www.opengis.net/wps/1.0.0"
 
xmlns:ows="http://www.opengis.net/ows/1.1"
 
xmlns:gml="http://www.opengis.net/gml"
 
xmlns:ogc="http://www.opengis.net/ogc"
 
xmlns:wcs="http://www.opengis.net/wcs/1.1.1"
 
xmlns:xlink="http://www.w3.org/1999/xlink"
 xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 
http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd;>

  gs:Clip

  



  features

 

Re: [Geoserver-users] [EXTERNAL] - RE: WPS gs:Clip Topology Exception

2022-03-24 Thread Oscar Wu
Hi Dominique,

Thank you very much for the suggestion.

I tried to explicitly define the EPSG in the getFeature request by adding 
srsName=EPSG:3005 to the url. The clipping geometry has no place to add SRS as 
it is only a geometry not a feature. However, I have made sure the coordinates 
in the clipping geometry are also generated under EPSG:3005. That being said, 
it unfortunately did not solve the issue.

Is there anything else I can try?

Thanks!

Oscar

From: Bessette-Halsema, Dominique E 
Sent: March 24, 2022 9:30 AM
To: Oscar Wu ; geoserver-users@lists.sourceforge.net 

Subject: [EXTERNAL] - RE: WPS gs:Clip Topology Exception


You may want to try specifying your EPSG in your Polygon and getFeature request



Dominique Bessette

Senior Software Engineer




From: Oscar Wu 
Sent: Wednesday, March 23, 2022 1:02 PM
To: geoserver-users@lists.sourceforge.net
Subject: [Geoserver-users] WPS gs:Clip Topology Exception





 [External: Use caution with links & attachments]



Hi everyone,



First time posting here, thank you for your understanding if I am not 
explaining my situation well.



I've been trying to use the built-in gs:Clip to extract some public layers 
based on a polygon defined by coordinates. The process seemed to work well with 
a couple of layers until I tried it with one particular layer.



Here's the xml in the POST request:

http://www.w3.org/2001/XMLSchema-instance; 
xmlns="http://www.opengis.net/wps/1.0.0;
 xmlns:wfs="http://www.opengis.net/wfs; 
xmlns:wps="http://www.opengis.net/wps/1.0.0; 
xmlns:ows="http://www.opengis.net/ows/1.1; 
xmlns:gml="http://www.opengis.net/gml; xmlns:ogc="http://www.opengis.net/ogc; 
xmlns:wcs="http://www.opengis.net/wcs/1.1.1; 
xmlns:xlink="http://www.w3.org/1999/xlink; 
xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 
http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd;>

  gs:Clip

  



  features

  http://openmaps.gov.bc.ca/geo/pub/ows?service=WFSversion=2.0.0request=GetFeaturetypeName=WHSE_CADASTRE.PMBC_PARCEL_FABRIC_POLY_SVWoutputFormat=jsonbbox=715319.3721917,1028613.368105,735025.9926936,1041407.195003;
 method="GET"/>





  clip

  



  



  

  



  result



  





In this case, a TopologyException was thrown (the stack trace is attached in 
the email):



org.locationtech.jts.geom.TopologyException: found non-noded intersection 
between LINESTRING ( 737930.4267 1033205.5095, 737925.915 1033208.5901 ) and 
LINESTRING ( 737933.8941 1033203.0284, 737930.4267 1033205.5095 ) [ 
(737930.4267, 1033205.5095, NaN) ]



I'm using Geoserver 2.20.2, GeoTools 26.2 and WPS 1.0.0.



I have searched about this issue and learned that this is caused by invalid 
geometry which was explained here:

https://locationtech.github.io/jts/jts-faq.html#D1



Then I tried to create a customized WPS that 'clean' the input either using 
buffer(0) or the GeometryFixer in JTS before sending it to the clip process but 
neither of them solved the issue.



I have exhausted my solutions to this problem and I'm wondering if anyone have 
encountered a similar issue before? May I have some suggestions about what to 
look for next?



Thank you very much!



Regards,



Oscar
___
Geoserver-users mailing list

Please make sure you read the following two resources before posting to this 
list:
- Earning your support instead of buying it, but Ian Turton: 
http://www.ianturton.com/talks/foss4g.html#/
- The GeoServer user list posting guidelines: 
http://geoserver.org/comm/userlist-guidelines.html

If you want to request a feature or an improvement, also see this: 
https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer


Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users