koopjs / koop

Transform, query, and download geospatial data on the web.
http://koopjs.github.io
Other
659 stars 127 forks source link

Getting an invalid GeoJSON warning #363

Closed gbreen12 closed 4 years ago

gbreen12 commented 4 years ago

I'm getting a warning with every request that my geoJSON is invalid. I don't believe it's invalid based on the spec.

The following is what I am returning from my getData method:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              1769555.21613184,
              7259500.73949967
            ],
            [
              1769567.964465922,
              7259505.727022502
            ],
            [
              1769631.2022003343,
              7259406.852548338
            ],
            [
              1769627.8770757476,
              7259404.734442321
            ],
            [
              1769620.224531994,
              7259400.091735086
            ],
            [
              1769618.6484196717,
              7259398.857157501
            ],
            [
              1769613.3292045824,
              7259395.045485326
            ],
            [
              1769609.9676627486,
              7259392.89489909
            ],
            [
              1769586.9408059188,
              7259378.804376092
            ],
            [
              1769584.7456003232,
              7259377.499260582
            ],
            [
              1769578.9742864182,
              7259374.414621076
            ],
            [
              1769573.013996507,
              7259371.713839086
            ],
            [
              1769566.8896649133,
              7259369.408725588
            ],
            [
              1769560.6275383409,
              7259367.509123079
            ],
            [
              1769554.2545195874,
              7259366.023233662
            ],
            [
              1769552.4408749184,
              7259365.72369358
            ],
            [
              1751204.2121515034,
              7248137.839325248
            ],
            [
              1751200.8627487575,
              7248133.7579685785
            ],
            [
              1751196.389332506,
              7248128.9820594955
            ],
            [
              1751191.6134234134,
              7248124.5086432425
            ],
            [
              1751186.554706502,
              7248120.357404835
            ],
            [
              1751177.891666084,
              7248114.368571663
            ],
            [
              1751126.0705754966,
              7248199.052785504
            ],
            [
              1751118.7628473374,
              7248210.994362662
            ],
            [
              1751066.941428669,
              7248295.678576508
            ],
            [
              1751074.9253365835,
              7248300.041428667
            ],
            [
              1751080.8859545882,
              7248302.742210659
            ],
            [
              1751087.010286162,
              7248305.047324167
            ],
            [
              1751093.2724127546,
              7248306.946926666
            ],
            [
              1751099.6451034115,
              7248308.432816085
            ],
            [
              1751099.8842761628,
              7248308.472186083
            ],
            [
              1769417.766931661,
              7259517.786709653
            ],
            [
              1769534.3828401663,
              7259488.239524669
            ],
            [
              1769555.21613184,
              7259500.73949967
            ]
          ]
        ]
      },
      "properties": {
        "displayId": 2,
        "shortName": "Water Hollow Tunnel",
        "name": "Water Hollow Tunnel"
      }
    }
  ],
  "metadata": {
    "geometryType": "Point",
    "idField": "displayId",
    "fields": [
      {
        "name": "displayId",
        "type": "Integer"
      },
      {
        "name": "shortName",
        "type": "String"
      },
      {
        "name": "name",
        "type": "String"
      }
    ]
  }
}
rgwozdz commented 4 years ago

It's just a warning. It probably means your polygon coordinates are not wound in the direction specified by the GeoJSON specification. You may be able to ignore it. If you have problems, you can rewind your geometry using https://github.com/mapbox/geojson-rewind.

If you want to suppress the warning set the environment variable: KOOP_WARNINGS=suppress .

Also - It looks like have set your geometryType wrong. It's set to Point, but you have Polygon data.

rgwozdz commented 4 years ago

Please paste the warning when you get a chance.

gbreen12 commented 4 years ago

WARNING: source data for /database/rest/services/FeatureServer/0/query contains invalid GeoJSON.

I guess I don't really care about the warning so much as I thought it might be messing me up. I'm able to get data back from my koop instance but when I try to use it in an esri map it doesn't show anything. I've narrowed it down to two parameters that are being used:

  1. outSR: If this is passed in koop returns features with no geometry
  2. geometry: I guess this is being used to return features that are within a certain area but no features ever get returned (in the process of testing this now, not sure if I'm just using a geometry that doesn't have any features in it)
rgwozdz commented 4 years ago

Ok, this is likely due to the coordiate system of your data, or the outSR you are requesting it to be served as. Does the GeoJSON you are creating in your provider have its coordinates in WGS84? Note that GeoJSON spec is for coordinates to be in WGS84, so that is what Koop is expecting to get from all providers.

Assuming your GeoJSON is in WGS84, you can run into problems when requests include an outSR. Unlike ArcGIS server, Koop doesn't contain full re-projection capabilities (at least out of the box); maintaining a complete dictionary of all potential coordinate system is currently considered outside of the scope of the application. Out of the box, koop only can manage a handful of outSR values. See this for more details, and this for a suggestion for supporting other outSRs in your provider.

gbreen12 commented 4 years ago

OK. I think I'm understanding now but I am not sure that Koop is the correct solution for us. Basically our data is already in the spatial reference we want but the Geoservices output plugin seems to assume it is in the WGS84 spatial reference so even if I do something like the following, it takes my data (which is already in the spatial reference we want) and tries to project it. Is the Geoservices plugin able to be customized to basically ignore the outSR and let me set the spatial reference to what I want on the way out? Again Koop may not end up being the correct solution... Thanks for your help.

rgwozdz commented 4 years ago

Right, Koop assumes it is WGS84 (GeoJSON spec). Currently this is critical for the GeoServices output plugin, because of the geometry filter. If Koop has to filter geometry, it has to compare the passed geometry enveloped to the data. Making this comparison means it needs to know the coordinate system of the data as well as that of the geometry envelope so that it can do the conversion so that it's apples to apples.

You can ignore outSR by removing it the before or after functions (or in the getData method if you are authoring a custom provider). Just set req.query.outSR = undefined. Whether or not this will cause you problems depends on the which clients you are using and the types of request they are making.

This issue has comes up for several other users. We're planning on adding a sourceSR parameter to handle it. For now, other users have taken the approach noted here. Essentially you get your data and reproject to WGS84 before Koop does anything else with it.

gbreen12 commented 4 years ago

OK Thanks for the info.