[gdal-dev] get_Area() Python

Travis Kirstine traviskirstine at gmail.com
Tue Dec 8 16:50:58 EST 2009


Hi all,
I'm trying a simple python script to calculate the polygon areas.  Are
the swig bindings for python working because is returning the geometry
type as -2147483645 the dimension and 2 for a 3d feature and the
get_Area returns a error?



#!/usr/bin/env python

from osgeo import ogr
import sys
import os

def get_file(dgn):

  dataset = ogr.Open(dgn)
  sql = 'SELECT * FROM elements WHERE Type=6'
  layer = dataset.ExecuteSQL(sql)
  feature = layer.GetNextFeature()

  while feature is not None:
    geom = feature.GetGeometryRef()
    type = geom.GetGeometryType()
    print 'Type =', type
    dim = geom.GetDimension()
    print 'Dimension =', dim
    area = geom.get_Area()
    print 'Area =', area

    # get the next feature
    feature.Destroy()
    feature = layer.GetNextFeature()

def main():
  # get a listing of all dgn in dir
  dlist = os.listdir('.')
  for item in dlist:
    if item[-4:] == '.dgn':
      get_file(item)


if __name__ == '__main__':
    main()

##############################################


Type = -2147483645
Dimension = 2
Traceback (most recent call last):
  File "./get_dgn_neatline.py", line 40, in ?
    main()
  File "./get_dgn_neatline.py", line 36, in main
    get_file(item)
  File "./get_dgn_neatline.py", line 21, in get_file
    area = geom.get_Area()
  File "/usr/lib/python2.4/site-packages/osgeo/ogr.py", line 2370, in <lambda>
    __getattr__ = lambda self, name: _swig_getattr(self, Geometry, name)
  File "/usr/lib/python2.4/site-packages/osgeo/ogr.py", line 34, in
_swig_getattr
    raise AttributeError,name
AttributeError: get_Area

###########################################

Had to open data source read-only.
INFO: Open of `car_01.dgn'
      using driver `DGN' successful.

Layer name: elements
Geometry: Unknown (any)
Feature Count: 438
Extent: (660241.900000, 4854102.500000) - (662678.200000, 4855934.400000)
Layer SRS WKT:
(unknown)
Type: Integer (2.0)
Level: Integer (2.0)
GraphicGroup: Integer (4.0)
ColorIndex: Integer (3.0)
Weight: Integer (2.0)
Style: Integer (1.0)
EntityNum: Integer (0.0)
MSLink: Integer (0.0)
Text: String (0.0)
OGRFeature(elements):74
  Type (Integer) = 6
  Level (Integer) = 22
  GraphicGroup (Integer) = 0
  ColorIndex (Integer) = 0
  Weight (Integer) = 0
  Style (Integer) = 0
  EntityNum (Integer) = (null)
  MSLink (Integer) = (null)
  Text (String) = (null)
  POLYGON ((662248.700000000069849 4854562.299999999813735 0,662249.0
4854562.5 0,662250.200000000069849 4854563.0 0,662251.40
0000000023283 4854563.400000000372529 0,662252.700000000069849
4854563.600000000558794 0,662254.100000000093132 4854563.700000
000186265 0,662255.5 4854563.5 0,662256.900000000023283
4854563.100000000558794 0,662258.200000000069849 4854562.4000000003725
29 0,662259.5 4854561.400000000372529 0,662258 4854562
0,662256.600000000093132 4854562.400000000372529
0,662255.2000000000698
49 4854562.5 0,662253.800000000046566 4854562.400000000372529
0,662252.5 4854562.100000000558794 0,662251.300000000046566 4854
561.600000000558794 0,662250.200000000069849 4854561.0
0,662249.200000000069849 4854560.200000000186265
0,662248.2000000000698
49 4854559.400000000372529 0,662247.400000000023283 4854558.5
0,662246.600000000093132 4854557.600000000558794 0,662246.0 4854
556.600000000558794 0,662245.600000000093132 4854555.700000000186265
0,662245.100000000093132 4854556.600000000558794 0,662244
.5 4854557.600000000558794 0,662243.800000000046566 4854558.5
0,662243.0 4854559.400000000372529 0,662242.100000000093132 4854
560.299999999813735 0,662241 4854561 0,662239.900000000023283
4854561.700000000186265 0,662238.800000000046566 4854562.1000000
00558794 0,662237.5 4854562.400000000372529 0,662236.200000000069849
4854562.600000000558794 0,662234.800000000046566 4854562.
400000000372529 0,662233.400000000023283 4854562.0
0,662231.900000000023283 4854561.299999999813735
0,662233.300000000046566 4
854562.400000000372529 0,662234.800000000046566
4854563.200000000186265 0,662236.300000000046566
4854563.600000000558794 0,662
237.800000000046566 4854563.600000000558794 0,662239.200000000069849
4854563.5 0,662240.600000000093132 4854563.10000000055879
4 0,662241.900000000023283 4854562.600000000558794
0,662243.100000000093132 4854562.0 0,662244.100000000093132
4854561.2000000
00186265 0,662245.0 4854560.900000000372529 0,662246.100000000093132
4854560.900000000372529 0,662247.0 4854561.20000000018626
5 0,662247.900000000023283 4854561.900000000372529
0,662248.700000000069849 4854562.299999999813735
0,662248.700000000069849 4
854562.299999999813735 0))


-- 
Travis K.


More information about the gdal-dev mailing list