[gdal-dev] Reading S57 Extents from Python
Mike Slinn
mslinn at mslinn.com
Thu Apr 17 11:19:02 EDT 2008
I realized after looking at the C++ code that entity extents are
returned as a tuple and not as a method call. In Python this means that
the extent coordinates can be accessed as slices:
print extents[:2], extents[2:]
Printing them out in Python is a bit tricky due to character encoding
issues, so here is an example that builds on my previous posting, in
case anyone ever has need of it:
def degreesNS(deg):
hemi = "N"
if deg<0:
hemi = "S"
return "%.3f%c%s" % (abs(deg), u'\N{DEGREE SIGN}', hemi)
def degreesEW(deg):
hemi = "E"
if deg<0:
hemi = "W"
return "%.3f%c%s" % (abs(deg), u'\N{DEGREE SIGN}', hemi)
extentStr = " Extents: (%s, %s) to (%s, %s)" % \
(degreesNS(extents[0]), degreesEW(extents[1]), \
degreesNS(extents[2]), degreesEW(extents[3]))
print extentStr.encode('utf-8')
Unfortunately, it looks like the layer extents are computed on every
call to layer.GetExtent() by reading every coordinate on that layer. If
one wants to know the extents of the entire data file, the call must be
made on every layer that has data. This doesn't scale well.
Section 7.4.1 of the S-57 spec (IHO Transfer Standard for Digital
Hydrographic Data, Edition 3.1, November 2000 - Main Document -
http://www.iho.shom.fr/publicat/free/files/31Main.pdf) discusses
Catalogue directory record structure. CATD(12) is the Catalogue
directory field, and it contains the extents for the entire chart,
referenced by subfields with labels (SLAT, WLON) to (NLAT, ELON). How
can this information be retrieved from Python?
Mike
More information about the gdal-dev
mailing list