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

Can't import geojson that contains various types of shapes #548

Closed
AngryGami opened this issue Jun 4, 2015 · 4 comments
Closed

Can't import geojson that contains various types of shapes #548

AngryGami opened this issue Jun 4, 2015 · 4 comments

Comments

@AngryGami
Copy link

When trying to do

CALL GeoJsonRead('my-points-and-polygons.geojson', 'SOME_TABLE');

I'm getting

Check constraint violation: "(PUBLIC.ST_GEOMETRYTYPECODE(THE_GEOM) = 3)"

i.e. it expect that all shapes in THE_GEOM column would be ONLY of type 3 (polygon)
while

CALL GeoJsonRead('only-polygons.geojson', 'SOME_TABLE');

works fine.
I beleive that this constraint is kinda too restrictive...

This wasn't an issue in version 1.1.1 and only appeared when I switched to 1.2.2.

I assume that this happening because previously SHPEngine.java file have following feedCreateTableData method definition:

 protected void feedCreateTableData(SHPDriver driver, CreateTableData data) throws IOException {
        if(data.columns.isEmpty()) {
            Column geometryColumn = new Column("THE_GEOM", Value.GEOMETRY);
            Parser parser = new Parser(data.session);
            geometryColumn.addCheckConstraint(data.session,
                    parser.parseExpression("ST_GeometryTypeCode(THE_GEOM) = "+getGeometryTypeCodeFromShapeType(driver.getShapeFileHeader().getShapeType())));
            data.columns.add(geometryColumn);
            DBFEngine.feedTableDataFromHeader(driver.getDbaseFileHeader(), data);
        }

and now it is

 protected void feedCreateTableData(SHPDriver driver, CreateTableData data) throws IOException {
        Column geometryColumn = new Column("THE_GEOM", Value.GEOMETRY);
        Parser parser = new Parser(data.session);
        geometryColumn.addCheckConstraint(data.session,
                parser.parseExpression("ST_GeometryTypeCode(THE_GEOM) = "+getGeometryTypeCodeFromShapeType(driver.getShapeFileHeader().getShapeType())));
        data.columns.add(geometryColumn);
        DBFEngine.feedTableDataFromHeader(driver.getDbaseFileHeader(), data);
@ebocher
Copy link
Member

ebocher commented Jun 4, 2015

Don't understand why you are talking about feedCreateTableData. Could you please send a copy of the input geojson my-points-and-polygons.geojson.

@AngryGami
Copy link
Author

This is the only place in the source code where "ST_GeometryTypeCode(THE_GEOM) =" constraint is actually created.
This is poligons and points

{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "geometry": {
            "type": "Polygon",
            "coordinates": [[[10.75672,
            59.93068800000001,
            0.0],
            [10.756943000000001,
            59.930689,
            0.0],
            [10.756994,
            59.930798,
            0.0],
            [10.756790000000002,
            59.930811,
            0.0],
            [10.75672,
            59.93068800000001,
            0.0]]]
        },
        "properties": {
            "NAME": "zone1"
        }
    },
    {
        "type": "Feature",
        "geometry": {
            "type": "Polygon",
            "coordinates": [[[10.756947,
            59.93068699999999,
            0.0],
            [10.756719,
            59.93068699999999,
            0.0],
            [10.756692,
            59.93057400000001,
            0.0],
            [10.756928,
            59.930586,
            0.0],
            [10.756947,
            59.93068699999999,
            0.0]]]
        },
        "properties": {
            "NAME": "zone2"
        }
    },
    {
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [10.7570381,
            59.930768300000004,
            0.0]
        },
        "properties": {
            "NAME": "Point 3"
        }
    },
    {
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [10.7568316,
            59.9307636,
            0.0]
        },
        "properties": {
            "NAME": "Point 4"
        }
    },
    {
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [10.7568061,
            59.9306251,
            0.0]
        },
        "properties": {
            "NAME": "Point 5"
        }
    },
    {
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [10.7574606,
            59.9307447,
            0.0]
        },
        "properties": {
            "NAME": "Point 6"
        }
    }]
}

and this is only polygons

{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "geometry": {
            "type": "Polygon",
            "coordinates": [[[10.756720300000001,
            59.930687600000006,
            0.0],
            [10.7569429,
            59.930689,
            0.0],
            [10.756993900000001,
            59.93079780000001,
            0.0],
            [10.75679,
            59.93081130000001,
            0.0],
            [10.756720300000001,
            59.930687600000006,
            0.0]]]
        },
        "properties": {
            "NAME": "zone1"
        }
    },
    {
        "type": "Feature",
        "geometry": {
            "type": "Polygon",
            "coordinates": [[[10.756946899999999,
            59.93068699999999,
            0.0],
            [10.7567189,
            59.93068699999999,
            0.0],
            [10.7566921,
            59.9305741,
            0.0],
            [10.7569281,
            59.9305862,
            0.0],
            [10.756946899999999,
            59.93068699999999,
            0.0]]]
        },
        "properties": {
            "NAME": "zone2"
        }
    }]
}

@ebocher
Copy link
Member

ebocher commented Jun 5, 2015

GeoJson reader doesn't support mixed geometry. We will look asap to fix that.

@ebocher ebocher modified the milestones: H2GIS 1.3 X, H2GIS 1.2 X Jun 12, 2015
nicolas-f added a commit that referenced this issue Jun 12, 2015
GeoJson supports now mixed geometries
About #548
@ebocher
Copy link
Member

ebocher commented Jun 12, 2015

Fixed #553

@ebocher ebocher closed this as completed Jun 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants