Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H2GIS (JTS) ST_Intersection behaviour vs PostGIS (GEOS) #1244

Open
ebocher opened this issue Jan 7, 2022 · 0 comments
Open

H2GIS (JTS) ST_Intersection behaviour vs PostGIS (GEOS) #1244

ebocher opened this issue Jan 7, 2022 · 0 comments
Labels

Comments

@ebocher
Copy link
Member

ebocher commented Jan 7, 2022

The following script fails in H2.

DROP TABLE IF EXISTS PARCELS,TRIANGLES,slope_by_parcels;
CREATE TABLE PARCELS (
	THE_GEOM GEOMETRY(MULTIPOLYGON)
);

INSERT INTO PARCELS VALUES('MULTIPOLYGON (((184661.64063 2431733.5, 184652.21875 2431759.5, 184646.03125 2431775, 184641.5 2431787.75, 184632.45313 2431812, 184620.78125 2431842, 184604.10938 2431886.25, 184602.92188 2431891, 184617.45313 2431898.25, 184662.6875 2431917.75, 184666.26563 2431915.25, 184675.79688 2431920, 184669.35938 2431943.75, 184684.125 2431946.75, 184704.84375 2431948.75, 184728.17188 2431948, 184758.89063 2431945.75, 184784.85938 2431944.25, 184844.85938 2431946.5, 184856.70313 2431947.75, 184906.40625 2431832, 184923.65625 2431795, 184939.10938 2431757, 184951.89063 2431723.25, 184968.25 2431670.5, 184969.8125 2431666.5, 184949.8125 2431668, 184890.95313 2431674.5, 184832.6875 2431680.5, 184761.32813 2431689.75, 184695.03125 2431698, 184673.17188 2431700.25, 184672.21875 2431705.25, 184670.79688 2431710, 184666.26563 2431720.75, 184661.64063 2431733.5)))'::geometry);

CREATE TABLE TRIANGLES (
	THE_GEOM GEOMETRY(POLYGONZ)
);


INSERT INTO PUBLIC.TRIANGLES
(THE_GEOM)
VALUES('POLYGON Z((184635.3007232633 2431979.9689098285 30, 184674.17520872923 2431843.505908667 35, 184698.06594086462 2431990.7904990697 30, 184635.3007232633 2431979.9689098285 30))'::GEOMETRY);

CREATE TABLE slope_by_parcels as SELECT st_intersection(a.the_geom, b.the_geom) as area_triangle FROM triangles as a, parcels as b;

It returns

Data conversion error converting "POLYGON ((184691.03034607897 2431947.4165794104, 184674.17520872923 2431843.505908667, 184654.0819511765 2431914.0402500452, 184662.6875 2431917.75, 184666.26563 2431915.25, 184675.79688 2431920, 184669.35938 2431943.75, 184684.125 2431946.75, 184691.03034607897 2431947.4165794104))"; SQL statement:

This is due to JTS that returns a new polygon with NaN Z.

String geomA_wkt = "MULTIPOLYGON (((184661.64063 2431733.5, 184652.21875 2431759.5, 184646.03125 2431775, 184641.5 2431787.75, 184632.45313 2431812, 184620.78125 2431842, 184604.10938 2431886.25, 184602.92188 2431891, 184617.45313 2431898.25, 184662.6875 2431917.75, 184666.26563 2431915.25, 184675.79688 2431920, 184669.35938 2431943.75, 184684.125 2431946.75, 184704.84375 2431948.75, 184728.17188 2431948, 184758.89063 2431945.75, 184784.85938 2431944.25, 184844.85938 2431946.5, 184856.70313 2431947.75, 184906.40625 2431832, 184923.65625 2431795, 184939.10938 2431757, 184951.89063 2431723.25, 184968.25 2431670.5, 184969.8125 2431666.5, 184949.8125 2431668, 184890.95313 2431674.5, 184832.6875 2431680.5, 184761.32813 2431689.75, 184695.03125 2431698, 184673.17188 2431700.25, 184672.21875 2431705.25, 184670.79688 2431710, 184666.26563 2431720.75, 184661.64063 2431733.5)))";
        String geomB_wkt = "POLYGON Z((184635.3007232633 2431979.9689098285 30, 184674.17520872923 2431843.505908667 35, 184698.06594086462 2431990.7904990697 30, 184635.3007232633 2431979.9689098285 30))";

        WKTReader wktReader = new WKTReader();
        Geometry geomA = wktReader.read(geomA_wkt);
        Geometry geomB = wktReader.read(geomB_wkt);

        Geometry result = geomA.intersection(geomB);

        System.out.println(new WKTWriter(3).write(result));

Print ->

POLYGON Z((184654.0819511765 2431914.0402500452 32.41562398679978, 184662.6875 2431917.75 NaN, 184666.26563 2431915.25 NaN, 184675.79688 2431920 NaN, 184669.35938 2431943.75 NaN, 184684.125 2431946.75 NaN, 184691.03034607897 2431947.4165794104 31.47245273727303, 184674.17520872923 2431843.505908667 35, 184654.0819511765 2431914.0402500452 32.41562398679978))

The same SQL script in PostGIS gives. All z values are filled (maybe with an interpolation plane ?)

POLYGON Z((184662.6875 2431917.75 30, 184666.26563 2431915.25 30, 184675.79688 2431920 30, 184669.35938 2431943.75 30, 184684.125 2431946.75 30, 184691.03034607897 2431947.4165794104 31.47245273727303, 184674.17520872923 2431843.505908667 35, 184654.0819511765 2431914.0402500452 32.41562398679978, 184662.6875 2431917.75 30))

We need to consult the specialist @dr-jts

ebocher added a commit to ebocher/H2GIS that referenced this issue Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant