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

geojson.UnmarshalGeometry() fails to detect an invalid geojson #63

Closed
aneeskA opened this issue Mar 24, 2021 · 3 comments
Closed

geojson.UnmarshalGeometry() fails to detect an invalid geojson #63

aneeskA opened this issue Mar 24, 2021 · 3 comments

Comments

@aneeskA
Copy link

aneeskA commented Mar 24, 2021

I have this geojson,

{
    "coordinates": [
        [
            [
                39.793632515714904,
                75.04223433164586
            ],
            null,
            [
                40.36804504271686,
                74.37994240330923
            ],
            [
                38.396554228796475,
                74.38108104787864
            ],
            [
                37.83643684788231,
                75.0431604849482
            ],
            [
                39.793632515714904,
                75.04223433164586
            ]
        ]
    ],
    "type": "Polygon",
    "srid": "epsg:4326"
}

which has a null in it. When I try to use the following code check if the above is good or not, my expectation is that geojson.UnmarshalGeometry will fail. But that is not happening.

        f, err := json.Marshal(_abovejson)
	if err != nil {
		return err
	}

	_footprint, err := geojson.UnmarshalGeometry(f)
	if err != nil {
		return err
	}

What am I missing?

@paulmach
Copy link
Owner

I haven't looked into the underlying reason but this seems to be how the standard encoding/json works. It just fills that coordinate location with the zero values which would be [0,0]

https://play.golang.org/p/oZdzCxh5V4t

I guess you'd have to manually unmarshal into something like []*orb.Point and see if there are any null values?

@aneeskA
Copy link
Author

aneeskA commented Mar 25, 2021

Yes, I did this experiment independently to arrive at the same conclusion :) Then I thought I was missing something obvious. What I need is something like Postgis' ST_IsValid() function. Do you have any recommendation for me?

@paulmach
Copy link
Owner

geojson validation is being discussed #45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants