[gdal-dev] Zonal statistics with GDAL/StarSpan

Greg Ederer greg at ergonosis.com
Fri Dec 19 17:04:19 EST 2008


Hi,

I performed the OpenJump procedure.  But, I still get:

Macintosh-4:starspan_tests gregederer$ starspan2 --progress --RID none 
--vector afadmn2n.shp --fid 3  --raster rfe_2006_04_pct.tif --stats  
results.txt avg --out-prefix bar --out-type table
Number of features: 550
starspan_csv:   1: Extracting from rfe_2006_04_pct.tif
        0% terminate called after throwing an instance of 
'geos::util::TopologyException'
  what():  TopologyException: side location conflict -8.25 23.1536
Abort trap

I noticed running the above does create a file called bar_table.csv.  
Here are the first few lines of this file:

FID,AREA,PERIMETER,AFADMN2N_,AFADMN2N_I,CNT_ABB,ADMIN2,FEWSID,CNTRY_NAME,VALUE,DEK_,SEAS_START,col,row,x,y,Band1
0,              23.2300000000000004,              
24.2429999999999986,               2,               2,MR,TIRIS 
ZEMMOUR,MR2TIRIS ZEMMOUR,Mauritania,               
2,,1,81,142,-12.050,25.950,99.041527
0,              23.2300000000000004,              
24.2429999999999986,               2,               2,MR,TIRIS 
ZEMMOUR,MR2TIRIS ZEMMOUR,Mauritania,               
2,,1,82,142,-11.950,25.950,99.358971
0,              23.2300000000000004,              
24.2429999999999986,               2,               2,MR,TIRIS 
ZEMMOUR,MR2TIRIS ZEMMOUR,Mauritania,               
2,,1,83,142,-11.850,25.950,99.358971
0,              23.2300000000000004,              
24.2429999999999986,               2,               2,MR,TIRIS 
ZEMMOUR,MR2TIRIS ZEMMOUR,Mauritania,               
2,,1,84,142,-11.750,25.950,99.358971
0,              23.2300000000000004,              
24.2429999999999986,               2,               2,MR,TIRIS 
ZEMMOUR,MR2TIRIS ZEMMOUR,Mauritania,               
2,,1,85,142,-11.650,25.950,98.070740
0,              23.2300000000000004,              
24.2429999999999986,               2,               2,MR,TIRIS 
ZEMMOUR,MR2TIRIS ZEMMOUR,Mauritania,               
2,,1,86,142,-11.550,25.950,98.705505
0,              23.2300000000000004,              
24.2429999999999986,               2,               2,MR,TIRIS 
ZEMMOUR,MR2TIRIS ZEMMOUR,Mauritania,               
2,,1,87,142,-11.450,25.950,99.999992

I happen to know that TIRIS ZEMMOUR, Mauritania shares a boundary with 
ADRAR, Mauritania.  The point, (-8.25, 23.1536), which appears in the 
TopologyException, lies on this boundary.  Maybe it got through Tiris 
Zemmour OK, then hung on Adrar for some reason.  Apparently, Tiris 
Zemmour has FID 0.  Maybe Adrar has FID 1, and starspan is iterating 
over the FIDs sequentially.  If these assumptions are correct, this 
would suggest a problem with the Adrar geometry.

So:

a) Is there some way to get a dump of FIDs with their corresponding 
country/province names?
b) What other steps might I take to detect/fix any side location conflict(s)
c) The docs on the starspan wiki are out of sync with the current 
version (1.2.03).  Are there updated docs for starspan?  Should I fall 
back to a previous version?

I greatly appreciate your help on this.

Best,

Greg

Brent Fraser wrote:
> Greg,
>
>  OpenJump is a good topology/geometry fixing tool.  Load your 
> shapefile and do Tools->Generate->Buffer, set the Buffer distance to 0 
> to clean up the polygon vertices.  I seem to recall it may have a 
> problem preserving attributes when the results are saved as a 
> shapefile, but you may be able to just use the new .shp portion with 
> the old .dbf and .shx if the resulting geometry records are not 
> re-ordered.
>
> Brent
>
>
>
> Greg Ederer wrote:
>> Brent,
>>
>> My Google search didn't turn up much of use (most of the results were 
>> PostGIS-specific).  Do you know of a tool that would tell me which 
>> feature(s) have problems?  Do you know of a tool that might be able 
>> to fix these polygons?
>>
>> Thanks!
>>
>> Greg
>>
>> Brent Fraser wrote:
>>> Greg,
>>>
>>>  It means the GEOS topology library is having problems with geometry 
>>> of your input shapefile.  Most likely related to duplicate vertices 
>>> (or near-duplicate) in a polygon.  Do a Google for "side location 
>>> conflict".   It would be nice if it spat out the FID of the 
>>> offending polygon...
>>>
>>> Brent
>>> Greg Ederer wrote:
>>>> Hi Brent,
>>>>
>>>> Thanks for the example.  Here's what I got:
>>>>
>>>> Macintosh-4:starspan_tests gregederer$ starspan2 --progress --RID 
>>>> none --vector 
>>>> /Users/gregederer/servers/geoserver_data/data/shapefiles/Admin/afadmn2n.shp  
>>>> --raster rfe_2006_04_pct.tif --stats  results.txt avg
>>>> starspan: --out-prefix: ?
>>>> Type `starspan --help' for help
>>>>
>>>> I then added a --out-prefix, like so:
>>>>
>>>> Macintosh-4:starspan_tests gregederer$ starspan2 --progress --RID 
>>>> none --vector 
>>>> /Users/gregederer/servers/geoserver_data/data/shapefiles/Admin/afadmn2n.shp  
>>>> --raster rfe_2006_04_pct.tif --stats  results.txt avg --out-prefix bar
>>>> starspan: --out-type: ?
>>>> Type `starspan --help' for help
>>>>
>>>> I then added '--out-type table' (I found in the source that valid 
>>>> --out-types are: table, mini_raster_strip, mini_rasters, 
>>>> rasterization):
>>>>
>>>> Macintosh-4:starspan_tests gregederer$ starspan2 --progress --RID 
>>>> none --vector 
>>>> /Users/gregederer/servers/geoserver_data/data/shapefiles/Admin/afadmn2n.shp  
>>>> --raster rfe_2006_04_pct.tif --stats  results.txt avg --out-prefix 
>>>> bar --out-type table
>>>> Number of features: 550
>>>> starspan_csv:   1: Extracting from rfe_2006_04_pct.tif
>>>>        0% terminate called after throwing an instance of 
>>>> 'geos::util::TopologyException'
>>>>  what():  TopologyException: side location conflict -8.25 23.1536
>>>> Abort trap
>>>>
>>>> Any idea what the TopologyException indicates?
>>>>
>>>> Thanks!
>>>>
>>>> Greg
>>>>
>>>> Brent Fraser wrote:
>>>>> Greg,
>>>>>
>>>>>  I've used StarSpan to do similar things; in my case I wanted 
>>>>> "mode" not "avg".  Using v1.2.01 (I don't think I made major mods 
>>>>> to the source):
>>>>>
>>>>>     starspan2.exe --progress --RID none --vector boundaries.shp  
>>>>> --raster big.tif --stats  results.txt mode
>>>>>
>>>>> I edited the resulting results.txt text (csv) file and used GDAL's 
>>>>> ogr2ogr to do a join on the shapefile's DBF file based on the FID.
>>>>>
>>>>> Brent Fraser
>>>>>
>>>>>
>>>>> Greg Ederer wrote:
>>>>>> Hello all,
>>>>>>
>>>>>> I'm a GDAL newbie.  I have a shape file containing subnational 
>>>>>> boundaries for Africa.  I have a raster containing rainfall for 
>>>>>> Africa.  I need to pull out the spatial average of rainfall for 
>>>>>> each of the subnational units.
>>>>>>
>>>>>> I think that I might be able to pull this off using StarSpan.  
>>>>>> But, the docs on the StarSpan wiki do not line up with the 
>>>>>> current version of the program (the changelog mentions that 
>>>>>> certain command line switches have been eliminated, and others 
>>>>>> added; but it doesn't say what the new switches do, or how to use 
>>>>>> them).  I am digging through the StarSpan sources to try to 
>>>>>> figure out how to use it.
>>>>>>
>>>>>> Does anyone have any suggestions as to how I might get the needed 
>>>>>> data using GDAL (with, or without StarSpan)?
>>>>>>
>>>>>> Thanks!
>>>>>>
>>>>>> Greg
>>>>>>
>>>>
>>>>
>>
>>


-- 
| E R G O N O S I S
| Greg Ederer
| Lead Developer
| greg at ergonosis.com
| 360.774.6848
|



More information about the gdal-dev mailing list