[gdal-dev] Questions about polygonization

John Twilley mathuin at gmail.com
Wed Aug 20 09:05:20 PDT 2014


Using qgis helped me see what you are saying.  The raster pixels are
being treated as rectangular areas but the actual coordinates are the
*corners* of those areas.  Modifying my code to offset the coordinates
by 0.5 causes the Contains test (and others) to produce results that
meet my expectations.

The really frustrating thing is that I think I had to learn this
already at least once over the past decade or so I've been tinkering
with GDAL.  I can't find a particularly embarrassing post in the
archives, but I'm confident it's there. :-)

Thank you for your patience.
--
mathuin at gmail dot com


On Tue, Aug 19, 2014 at 7:32 PM, Chaitanya kumar CH
<chaitanya.ch at gmail.com> wrote:
> Try qgis to display the raster and the vector output. It shows the raster
> pixels as rectangular areas. To confirm that there is no shift, compare
> their extents using gdalinfo and ogrinfo.
>
> On 20 Aug 2014 07:56, "John Twilley" <mathuin at gmail.com> wrote:
>>
>> The program is not shifting the pixels, but the program does assume
>> the pixels to be points and not rectangular areas so maybe I will have
>> to shift the pixels.  Do you know what transformation I would need to
>> use?
>>
>> Jack.
>> --
>> mathuin at gmail dot com
>>
>>
>> On Tue, Aug 19, 2014 at 7:17 PM, Chaitanya kumar CH
>> <chaitanya.ch at gmail.com> wrote:
>> > Jack,
>> > The GDALPolygonize algorithm draws the polygon edges along the pixel
>> > edges.
>> > It assumes the pixels to be rectangular areas instead of points.
>> > In the example you described, the first polygon should contain four
>> > vertices
>> > with the pixel in the centre.
>> > Make sure that the program you are using to display them is not shifting
>> > the
>> > pixels.
>> >
>> > On 20 Aug 2014 07:12, "John Twilley" <mathuin at gmail.com> wrote:
>> >>
>> >> I am trying to use GDAL's polygonize algorithms to help me identify
>> >> regions in landcover data.  I made a trivial example, but I am having
>> >> trouble understanding the results that I get, nor can I determine how
>> >> to get the results I want.
>> >>
>> >> Given the following raster:
>> >>
>> >> 11 11 11 11 11
>> >> 11 11 11 11 11
>> >> 11 11 12 11 11
>> >> 11 11 11 11 11
>> >> 11 11 11 11 11
>> >> 11 11 11 11 11
>> >>
>> >> If I were to polygonize this raster, I would expect two polygons:  one
>> >> which contains the single point 12, and another with an outer ring was
>> >> the perimeter of the raster and an inner ring circling the single
>> >> point 12.  I would also expect that the first polygon would contain
>> >> the single point 12 and that the second polygon would contain all the
>> >> points 11.
>> >>
>> >> Instead, what I got was a polygon starting from the single point 12
>> >> and extending down and to the right one pixel, and another polygon
>> >> with an outer ring that went off the down and right edges and an inner
>> >> ring equal to the first polygon's outer ring.  The first polygon
>> >> doesn't actually contain any points and the second one doesn't contain
>> >> any points on either ring but does contain all the other points.
>> >>
>> >> What do I need to do to get the results I am expecting?
>> >>
>> >> Jack.
>> >> --
>> >> mathuin at gmail dot com
>> >> _______________________________________________
>> >> gdal-dev mailing list
>> >> gdal-dev at lists.osgeo.org
>> >> http://lists.osgeo.org/mailman/listinfo/gdal-dev


More information about the gdal-dev mailing list