<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div>Hi,</div><div> </div><div>I don't have a WKT format as such (sorry but I'm learning about all this as I go), all I do have is a simple Python script that creates the shapefiles. The idea of having T3 inside T2 with both inside /t1 is correct in this case but not necessarily always the case. T2 & T3 could both be inside T1 side by side.</div><div> </div><div>The content of the python script file is as follows (the polygons are T1, T2, T3 in order):</div><div> </div><div>import shapefile</div><div>outfile =
shapefile.Writer(shapefile.POLYGON)</div><div>outfile.poly(parts=[\</div><div>[[easting,northing],[easting,northing],[easting,northing],[easting,northing],\</div><div>[easting,northing],[easting,northing],[easting,northing],[easting,northing]],\</div><div>[[easting,northing],[easting,northing],[easting,northing],[easting,northing]]\</div><div>])</div><div>outfile('Location','C','20')</div><div>outfile.record('One')</div><div>outfile.save('nestedpolygon')</div><div> </div><div>I've replaced to values with northing and easting to save having to enter the figures (I can't include the file).</div><div> </div><div>I'm sure my mistake is obvious but as I'm still pretty much a beginner I can't see it :(</div><div> </div><div>All suggestions are welcome.</div> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr">
<div class="hr" style="margin: 5px 0px; padding: 0px; border: 1px solid rgb(204, 204, 204); height: 0px; line-height: 0; font-size: 0px;" contenteditable="false" readonly="true"></div> <font face="Arial" size="2"> <b><span style="font-weight: bold;">From:</span></b> Even Rouault <even.rouault@spatialys.com><br> <b><span style="font-weight: bold;">To:</span></b> Graeme Wilkie <graeme.wilkie@btinternet.com> <br><b><span style="font-weight: bold;">Cc:</span></b> "gdal-dev@lists.osgeo.org" <gdal-dev@lists.osgeo.org> <br> <b><span style="font-weight: bold;">Sent:</span></b> Friday, August 8, 2014 2:27 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [gdal-dev] GDAL, ESRI Shapefiles and nested polygons<br> </font> </div> <div class="y_msg_container"><br>Le vendredi 08 août 2014 15:19:38, Graeme Wilkie a écrit :<br>> Hi,<br>> <br>> You were correct, it is returning multipolygon (9sorry, I should
have<br>> included that information). <br>> I've made the change you suggested so the code looks like<br>> Int index = 0;<br>> OGRGeometryH hGeometry = OGR_F_GetGeometryRef(hFeature);<br>> int shape_type = wkbFlatten(ORG_G_GetGeometry(hGeometry);<br>> int num_geom = OGR_G_GetGeometryCount(hGeometry) - 1; // Returns a valid<br>> result int innerIndex = 0;<br>> <br>> do<br>> {<br>> OGRGeometryH hRing = OGR_G_GetGeometryRef(hGeometry,<br>> index); OGRGeometryH tmpGeo = OGR_G_GetGeometryRef(hRing, innerIndex); Int<br>> num_vertices = OGR_G_GetPointCount(tmpGeo);<br>> //.<br>> //. Do something with the data<br>> //.<br>> Index++;<br>> }<br>> // Destroy the hfeature here<br>> )<br>> <br>> If innerIndex is 0 then I can read the data for that polygon. If
innerIndex<br>> in 1 then tmpGeo is NULL even though there are 2 inner polygons in the<br>> test data. <br>> Have I do something stupid ?<br>> <br>> The test data is a simple square with 2 squares inside it created using<br>> shapefile.py <br><br>You still didn't include the WKT... Well I will assume that you have square T3 <br>included inside square T2 included inside square T1.<br><br>In that case the structure of the WKT should be ((T1,T2),T3)<br>i.e. a multipolygon with 2 polygons : (T1,T2) and T3<br>T1 is an outer ring<br>T2 an inner ring of T1<br>T3 an outer ring<br>That's the way polygons are modelised in SFS specification.<br><br>> If anybody has a small piece of example could it would be a great help.<br>> <br>> Regards<br>> <br>> Graeme<br>> <br>> ________________________________<br>> From: Even Rouault <<a href="mailto:even.rouault@spatialys.com"
ymailto="mailto:even.rouault@spatialys.com">even.rouault@spatialys.com</a>><br>> To: <a href="mailto:gdal-dev@lists.osgeo.org" ymailto="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>> Cc: Graeme Wilkie <<a href="mailto:graeme.wilkie@btinternet.com" ymailto="mailto:graeme.wilkie@btinternet.com">graeme.wilkie@btinternet.com</a>><br>> Sent: Thursday, August 7, 2014 9:26 PM<br>> Subject: Re: [gdal-dev] GDAL, ESRI Shapefiles and nested polygons<br>> <br>> Le jeudi 07 août 2014 22:20:34, Graeme Wilkie a écrit :<br>> > Hi,<br>> > <br>> > I'm trying to use GDAL to read ESRI shapefiles. I've got it working for<br>> > points, lines, polygons, polylines and multipoint but I'm having problems<br>> > with polygons that contain polygons in the same feature.<br>> > <br>> > <br>> > <br>> > The following is a cut down code sample of the code I'm using. The<br>> >
problem I have is that I can read the number of polygons in the feature<br>> > (i.e. 3 polygons, nested) using OGR_G_GetGemoetryCount. When I use<br>> > OGR_R_GetGeometryRef to get the handle/pointer for each of the polygons<br>> > in turn I get what appears to be a valid handle but when I use it to get<br>> > the number of points/vertices in the polygon it always returns 0.<br>> <br>> Graeme,<br>> <br>> You didn't display the WKT that corresponds to the geometry, so I will just<br>> make the guess that the geometries returned is a multipolygon and not a<br>> polygon.<br>> <br>> So you might need one more level of OGR_G_GetGeometryCount and<br>> OGR_G_GetGeometryRef to go to the ring level.<br>> <br>> Best regards,<br>> <br>> Even<br><br>-- <br>Spatialys - Geospatial professional services<br><a href="http://www.spatialys.com/" target="_blank">http://www.spatialys.com/</a><br><br><br></div>
</div> </div> </div></body></html>