[FWTools] Centroid Error
Travis Kirstine
traviskirstine at gmail.com
Tue Apr 3 14:19:30 EDT 2007
All,
I have written a simple python script to get the centroid of a .shp
polygon and and the x/y to new fields. The script works fine for the
most part but fails on certain features within the shapefile. After
looking into the matter a little more the features that script fails
on are MULTIPOLGONs. I tried to force the .shp to POLYGON using
ogr2ogr with the command opition -lco SHPT=POYGON but the output is
the same as the orginal. Any ideas on forcing the output have only
"POLYGON" features.
Script Error:
ERROR 1: Invoked Centroid() on non-Polygon.
Traceback (most recent call last):
File "C:\PROGRA~1\FWTOOL~1.3\bin\calculate_centroid.py", line 122, in ?
centroid = feature.GetGeometryRef().Centroid()
File "C:\PROGRA~1\FWTOOL~1.3\pymod\ogr.py", line 1164, in Centroid
raise OGRError, 'Error in Centroid operation. ' + _gdal.CPLGetLastErrorMsg(
)
ogr.OGRError: Error in Centroid operation. Invoked Centroid() on non-Polygon.
ogrinfo of polygon
Layer name: error_poly
Geometry: Polygon
Feature Count: 1
Extent: (647330.017661, 4851582.390811) - (647611.869278, 4851834.563811)
Layer SRS WKT:
PROJCS["NAD83 / UTM zone 17N",
GEOGCS["NAD83",
DATUM["North_American_Datum_1983",
SPHEROID["GRS 1980",6378137.0,298.257222101]],
PRIMEM["Greenwich",0.0],
UNIT["degree",0.01745329251994328]],
PROJECTION["Transverse_Mercator"],
PARAMETER["false_easting",500000.0],
PARAMETER["false_northing",0.0],
PARAMETER["central_meridian",-81.0],
PARAMETER["scale_factor",0.9996],
PARAMETER["latitude_of_origin",0.0],
UNIT["metre",1.0]]
PIN: String (9.0)
LRO: Integer (9.0)
ARN: String (20.0)
ST_NAME: String (34.0)
ST_NUMBER: Integer (9.0)
SUFFIX: String (6.0)
MUNICIPAL: String (24.0)
DESCRIPT: String (254.0)
OGRFeature(error_poly):0
PIN (String) = 00000001
LRO (Integer) = 80
ARN (String) = 1123456789
ST_NAME (String) = GENER BOULEVARD
ST_NUMBER (Integer) = 41
SUFFIX (String) = (null)
MUNICIPAL (String) = SCAR
DESCRIPT (String) = (null)
MULTIPOLYGON (((647523.81994185271 4851827.553924364,647531.3266283978 4851829
.9495709538,647538.97239421296 4851831.8552978765,647546.72528310469 4851833.263
1366197,647554.55292813084 4851834.1672340259,647562.42263375153 4851834.5638112
128,647570.30151958973 4851834.4511841126,647578.15666419407 4851833.829845625,6
47585.95526933717 4851832.7023834614,647593.66476270347 4851831.0735006854,64760
1.25294165022 4851828.9500157153,647608.68807589496 4851826.3407801688,647606.54
436158587 4851813.0243918709,647573.22462821414 4851801.2041120613,647554.553585
3277 4851794.5803283257,647554.44566129264 4851794.8847747371,647548.70057019952
4851792.8466226626,647548.49722940591 4851793.4209921174,647546.45907733089 485
1799.1660832101,647533.53433724411 4851794.5803899374,647535.57250985655 4851788
.8360998034,647536.39392369147 4851786.5206928328,647537.60986097308 4851783.091
0497848,647538.32793061319 4851783.3455081657,647547.90712830285 4851756.3452558
797,647549.43552158203 4851752.0363451419,647549.24351743306 4851751.9680582881,
647546.37119779794 4851750.9493827298,647544.74387586466 4851750.1770327426,6475
43.30683293892 4851749.0909739761,647542.11964801687 4851747.7362449476,647541.2
3161085753 4851746.1690565208,647540.68122908531 4851744.4578598477,647540.48772
570607 4851742.6707774829,647540.611114403 4851741.1455880376,647540.99534861243
4851739.6644307775,647564.81957419775 4851672.4979332853,647566.85731552495 485
1666.7528627291,647571.28912206239 4851654.2572721448,647565.3488435233 4851652.
1509769782,647565.86468138942 4851650.6981613291,647566.88333641016 4851647.8254
309464,647567.59031585453 4851645.8315369673,647572.7613866285 4851647.665116004
6,647574.03776547709 4851644.0661831712,647574.78873603139 4851641.9488799581,64
7575.56899291754 4851639.748379739,647582.46284345805 4851642.1939938227,647609.
32138768688 4851651.7227105843,647611.86927802034 4851644.5418498833,647563.3947
5102478 4851627.3449610043,647561.07774213771 4851626.5232185703,647546.71526085
364 4851621.4278691895,647436.59249188029 4851582.3908112887,647339.86454353342
4851730.732489774,647331.10971706419 4851755.4131659986,647330.09028162214 48517
58.2867178777,647330.01766137709 4851758.4900997458,647331.36941248225 4851759.2
146797413,647332.78706810286 4851759.7998313317,647346.5560390756 4851764.683111
5242,647471.55581280566 4851809.0173398331,647474.42854318884 4851810.0364056015
,647479.16526849836 4851811.7159541417,647490.65257544874 4851815.7903893888,647
492.69074806129 4851810.0460992539,647496.99924805143 4851811.5741228601,647494.
96105490159 4851817.318412995,647523.81994185271 4851827.553924364)),((647346.55
60390756 4851764.6831115242,647349.86759207631 4851756.1605630452,647342.7654101
5401 4851753.4013839439,647340.55784506956 4851759.0832198467,647339.4538571533
4851761.9239529613,647346.5560390756 4851764.6831115242)))
--
Travis K.
Toronto, Canada
------------------------------------------------------------
"She knows there's no success like failure
And that failure's no success at all."
-Bob Dylan-
------------------------------------------------------------
More information about the FWTools
mailing list