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&version=2.0.0&request=GetFeature&typeName=WHSE_CADASTRE.PMBC_PARCEL_FABRIC_POLY_SVW&outputFormat=json&bbox=715319.37219999917,1027297.6436000001,735025.99269999936,1041407.1950000003> 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 <oscar...@crmltd.ca> Sent: March 24, 2022 4:29 PM To: Bessette-Halsema, Dominique E <dominique.besse...@gdit.com>; geoserver-users@lists.sourceforge.net <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 <dominique.besse...@gdit.com> Sent: March 24, 2022 11:45 AM To: Oscar Wu <oscar...@crmltd.ca>; geoserver-users@lists.sourceforge.net <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 <oscar...@crmltd.ca> Sent: Thursday, March 24, 2022 11:23 AM To: Bessette-Halsema, Dominique E <dominique.besse...@gdit.com>; 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 <dominique.besse...@gdit.com<mailto:dominique.besse...@gdit.com>> Sent: March 24, 2022 9:30 AM To: Oscar Wu <oscar...@crmltd.ca<mailto:oscar...@crmltd.ca>>; geoserver-users@lists.sourceforge.net<mailto:geoserver-users@lists.sourceforge.net> <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 <oscar...@crmltd.ca<mailto:oscar...@crmltd.ca>> Sent: Wednesday, March 23, 2022 1:02 PM To: geoserver-users@lists.sourceforge.net<mailto: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: <?xml version="1.0" encoding="UTF-8"?><wps:Execute version="1.0.0" service="WPS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance<https://urldefense.us/v3/__http:/www.w3.org/2001/XMLSchema-instance__;!!JRQnnSFuzw7wjAKq6ti6!gDSMzRRYpMIJOdp0JULuHTOMdeDoSlcttXPgVVdrVhMIp52bZxlKBiaq4bqpMlI2ApylXA$>" xmlns="http://www.opengis.net/wps/1.0.0"<https://urldefense.us/v3/__http:/www.opengis.net/wps/1.0.0*22__;JQ!!JRQnnSFuzw7wjAKq6ti6!lWi8-ZpfeBpVXzABGU-5yNnZNU21PJH7Uuw1mhAHL4oaSnQZGvwCFV3FQ_4yHdJ6SAxCew$> xmlns:wfs="http://www.opengis.net/wfs<https://urldefense.us/v3/__http:/www.opengis.net/wfs__;!!JRQnnSFuzw7wjAKq6ti6!gDSMzRRYpMIJOdp0JULuHTOMdeDoSlcttXPgVVdrVhMIp52bZxlKBiaq4bqpMlKp1Xbehw$>" xmlns:wps="http://www.opengis.net/wps/1.0.0<https://urldefense.us/v3/__http:/www.opengis.net/wps/1.0.0__;!!JRQnnSFuzw7wjAKq6ti6!gDSMzRRYpMIJOdp0JULuHTOMdeDoSlcttXPgVVdrVhMIp52bZxlKBiaq4bqpMlIn312I5A$>" xmlns:ows="http://www.opengis.net/ows/1.1<https://urldefense.us/v3/__http:/www.opengis.net/ows/1.1__;!!JRQnnSFuzw7wjAKq6ti6!gDSMzRRYpMIJOdp0JULuHTOMdeDoSlcttXPgVVdrVhMIp52bZxlKBiaq4bqpMlKeD7F_oQ$>" xmlns:gml="http://www.opengis.net/gml<https://urldefense.us/v3/__http:/www.opengis.net/gml__;!!JRQnnSFuzw7wjAKq6ti6!gDSMzRRYpMIJOdp0JULuHTOMdeDoSlcttXPgVVdrVhMIp52bZxlKBiaq4bqpMlK_I__oxQ$>" xmlns:ogc="http://www.opengis.net/ogc<https://urldefense.us/v3/__http:/www.opengis.net/ogc__;!!JRQnnSFuzw7wjAKq6ti6!gDSMzRRYpMIJOdp0JULuHTOMdeDoSlcttXPgVVdrVhMIp52bZxlKBiaq4bqpMlKdc1gmIw$>" xmlns:wcs="http://www.opengis.net/wcs/1.1.1<https://urldefense.us/v3/__http:/www.opengis.net/wcs/1.1.1__;!!JRQnnSFuzw7wjAKq6ti6!gDSMzRRYpMIJOdp0JULuHTOMdeDoSlcttXPgVVdrVhMIp52bZxlKBiaq4bqpMlKB59KQsg$>" xmlns:xlink="http://www.w3.org/1999/xlink<https://urldefense.us/v3/__http:/www.w3.org/1999/xlink__;!!JRQnnSFuzw7wjAKq6ti6!gDSMzRRYpMIJOdp0JULuHTOMdeDoSlcttXPgVVdrVhMIp52bZxlKBiaq4bqpMlJsVIAlgQ$>" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd"><https://urldefense.us/v3/__http:/schemas.opengis.net/wps/1.0.0/wpsAll.xsd*22*3E__;JSU!!JRQnnSFuzw7wjAKq6ti6!lWi8-ZpfeBpVXzABGU-5yNnZNU21PJH7Uuw1mhAHL4oaSnQZGvwCFV3FQ_4yHdLoTCpOtw$> <ows:Identifier>gs:Clip</ows:Identifier> <wps:DataInputs> <wps:Input> <ows:Identifier>features</ows:Identifier> <wps:Reference mimeType="application/json" xlink:href="http://openmaps.gov.bc.ca/geo/pub/ows?service=WFS&version=2.0.0&request=GetFeature&typeName=WHSE_CADASTRE.PMBC_PARCEL_FABRIC_POLY_SVW&outputFormat=json&bbox=715319.37219999917,1028613.3681000005,735025.99269999936,1041407.1950000003<https://urldefense.us/v3/__http:/openmaps.gov.bc.ca/geo/pub/ows?service=WFS&version=2.0.0&request=GetFeature&typeName=WHSE_CADASTRE.PMBC_PARCEL_FABRIC_POLY_SVW&outputFormat=json&bbox=715319.37219999917,1028613.3681000005,735025.99269999936,1041407.1950000003__;!!JRQnnSFuzw7wjAKq6ti6!gDSMzRRYpMIJOdp0JULuHTOMdeDoSlcttXPgVVdrVhMIp52bZxlKBiaq4bqpMlL1jQPNsQ$>" method="GET"/> </wps:Input> <wps:Input> <ows:Identifier>clip</ows:Identifier> <wps:Data> <wps:ComplexData mimeType="application/json"><![CDATA[{"type":"Polygon","coordinates":[[[715354.52820000052,1040603.9793999996],[715319.37219999917,1028613.3681000005],[734339.38680000044,1027297.6436000001],[735025.99269999936,1041407.1950000003],[715354.52820000052,1040603.9793999996]]]}]]></wps:ComplexData> </wps:Data> </wps:Input> </wps:DataInputs> <wps:ResponseForm> <wps:RawDataOutput mimeType="application/json"> <ows:Identifier>result</ows:Identifier> </wps:RawDataOutput> </wps:ResponseForm> </wps:Execute> 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<https://urldefense.us/v3/__https:/locationtech.github.io/jts/jts-faq.html*D1__;Iw!!JRQnnSFuzw7wjAKq6ti6!lWi8-ZpfeBpVXzABGU-5yNnZNU21PJH7Uuw1mhAHL4oaSnQZGvwCFV3FQ_4yHdLUVD9nQw$> 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