PyGeoj icon indicating copy to clipboard operation
PyGeoj copied to clipboard

support update_bbox() also for of coordinates with elevation data

Open udos opened this issue 6 years ago • 1 comments

it would be nice if update_bbox() would also work for features with coordinates that contain elevation data (as optional 3rd element).

currently an error is thrown.

the geojson specs do forsee an optional 3rd elevation element in the coordinate array (https://tools.ietf.org/html/rfc7946#section-3.1.1):

A position is an array of numbers. There MUST be two or more elements. The first two elements are longitude and latitude, or easting and northing, precisely in that order and using decimal numbers. Altitude or elevation MAY be included as an optional third element.

the error can be reproduced as following:

newfile = pygeoj.new()
newfile.add_feature(
    properties={"country": "Norway"},
    geometry={"type": "Polygon", "coordinates": [[(21, 3, 120), (33, 11, 400), (44, 22, 234)]]}
)
newfile.update_bbox()

and the error:

  File "/Users/udos/.virtualenvs/ts/lib/python3.6/site-packages/pygeoj.py", line 662, in update_bbox
    xmins, ymins, xmaxs, ymaxs = zip(*(feat.geometry.bbox for feat in self if feat.geometry.type != "Null"))
  File "/Users/udos/.virtualenvs/ts/lib/python3.6/site-packages/pygeoj.py", line 662, in <genexpr>
    xmins, ymins, xmaxs, ymaxs = zip(*(feat.geometry.bbox for feat in self if feat.geometry.type != "Null"))
  File "/Users/udos/.virtualenvs/ts/lib/python3.6/site-packages/pygeoj.py", line 232, in bbox
    for _x,_y in coordsgen:
ValueError: too many values to unpack (expected 2)

udos avatar Feb 05 '19 19:02 udos

That would be a good feature. I won't have time to add this for a while, but I will gladly accept a PR if you or someone is able to implement this.

karimbahgat avatar Jul 15 '19 12:07 karimbahgat