0

I have converted a geoJSON file to shp using ogr2ogr, and everything is as expected - except any values that are negative in the JSON end up being positive once the file is converted to shp.

For example :

JSON : "-45" - Correct before converting

SHP : "45" - Wrong after converting

Here is the command I have used :

ogr2ogr -nlt POLYGON -skipfailures polygons.shp geojsonfile.json 

Am I missing something? I looked in the documentation for ogr2ogr and I don't see anything about negatives. An actual example for one feature is below. Note the value that is "-7.5", but it is "7.5" after being converted to a shapefile. I confirmed this in QGIS.

{
    "type": "Feature",
    "geometry": {      "type": "Polygon",
      "coordinates": [
        [
          [-98.09436584736005, 29.62865606187322],
          [-98.09594335852961, 29.626871027805652],
          [-98.0970915224778, 29.62765563489956],
          [-98.09548731746852, 29.62942243552636],
          [-98.09436584736005, 29.62865606187322]
        ]
      ]
     },
     "properties": {
        "sweep": 0,
        "sweepTime": "2017-02-20T04:40:19Z",
        "elevAngle": 0.6893921,
        "value": -7.5,  // Does not convert properly as a negative value
        "radialAng": 218.172,
        "begGateRan": 10499.548,
        "endGateRan": 10749.536,
        "heightRel": 132.83063,
        "heightASL": 325.769
     }
   }
1

Works for me with GDAL 3.1.0dev

ogr2ogr -f "ESRI Shapefile" negative.shp negative.json
Warning 6: Field sweepTime create as date field, though DateTime requested.

ogrinfo negative.shp -al
INFO: Open of `negative.shp'
      using driver `ESRI Shapefile' successful.

Layer name: negative
Metadata:
  DBF_DATE_LAST_UPDATE=2020-03-23
Geometry: Polygon
Feature Count: 1
Extent: (-98.097092, 29.626871) - (-98.094366, 29.629422)
Layer SRS WKT:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["latitude",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["longitude",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    ID["EPSG",4326]]
Data axis to CRS axis mapping: 2,1
sweep: Integer (9.0)
sweepTime: Date (10.0)
elevAngle: Real (24.15)
value: Real (24.15)
radialAng: Real (24.15)
begGateRan: Real (24.15)
endGateRan: Real (24.15)
heightRel: Real (24.15)
heightASL: Real (24.15)
OGRFeature(negative):0
  sweep (Integer) = 0
  sweepTime (Date) = 2017/02/20
  elevAngle (Real) = 0.689392100000000
  value (Real) = -7.500000000000000
  radialAng (Real) = 218.171999999999997
  begGateRan (Real) = 10499.548000000000684
  endGateRan (Real) = 10749.536000000000058
  heightRel (Real) = 132.830630000000014
  heightASL (Real) = 325.769000000000005
  POLYGON ((-98.0943658473601 29.6286560618732,-98.0959433585296 29.6268710278057,-98.0970915224778 29.6276556348996,-98.0954873174685 29.6294224355264,-98.0943658473601 29.6286560618732))
| improve this answer | |
  • Well, this is odd. I am not an expert with gdal by any means, but I don't see what I could have done wrong. I am using gdal through conda - version 3.0.4 from this year. Surely that isn't old enough to cause an issue. – David Mar 23 at 8:52
  • Does ogrinfo geojsonfile.json -al show the value with minus sign? Does conversion into GeoPackage work as supposed? – user30184 Mar 23 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.