[FWTools] ogr2ogr shp --> kml conversion failing on
some complicated polygons
Bryan Keith
bryan at geomega.com
Fri Apr 13 10:47:15 EDT 2007
I solved this problem with some help from Google:
http://groups.google.com/group/kml-support-getting-started/browse_thread/thread/e6995b8073e69c41
The problem turned out to be that Google has a limit on the number of
vertices in a polygon. My solution was to dump the dataset into postgis
and simplify the large polygons. I did something like this:
ogr2ogr -sql "select admin, case when area(the_geom) > 3000000000 then
transform(simplify(the_geom, 4), 4030) else transform(simplify(the_geom,
0.01), 4030) end from utlanduse" -f kml out.kml PG:"host=localhost
user=xxx dbname=statewide password=xxx"
The simplified polygons display without a problem in Google Earth.
Bryan
Bryan Keith wrote:
> Lennox Antoine wrote:
>> Hi Brian,
>>
>> It appears it's either a tesselation issue on Google's side, or your input
>> data is bad. I don't which application you're using to view your vector
>> files, but out of the three I used, 2 of them displayed one way, and 1 was
>> corrupt (see inner_real2.png).
>
> Lennox,
>
> That's interesting. I'm looking at the shapefile in MapWindow GIS which
> displays it like OpenEV and TatukGIS do. Maybe I need to figure out why
> QGIS doesn't like the shapefile, fix it, and google will like it as
> well. Maybe a simplification algorithm would help.
>
>> Based on these results, I have to assume FWTools and TatukGIS are the
>> correct ways of viewing the vector file. The problem with the KML file in
>> this case though, is that it only has 3 inner polygons.
>
> No, the kml file I sent you is the simplest kml file I was able to
> create that doesn't display correctly. It's not direct output from the
> kml generator. Sorry for the confusion.
>
>> Look closely at the
>> screenshot comparison. There are many little innerpolyons. You can't
>> represent all those holes with only 3 innerpolygons. I removed the last
>> innerpolygon (which was the biggest), and it appears that two little holes
>> show up in GE (inner.png).
>
> I generated lots of kml files with different innerpolygons. If you
> remove any single innerpolygon from the file that has 3 (and doesn't
> work), then the file with 2 innerpolygons displays correctly. I also
> made a file that had 35 of the 38 innerpolygons and that file displayed
> correctly as well.
>
>> What this concludes, is that GE is probably renderring correctly, and so is
>> FWTools and TatukGIS. The problem probably lies in the KML generator, not
>> outputting the correct inner polygons.
>
> No, see above.
>
> Unfortunately I still don't understand the problem well enough to be
> able to avoid it and generate good kml files.
>
> Bryan
>
>> -Lennox
>>
>>
>> On 4/8/07, Bryan Keith <bryan at geomega.com> wrote:
>>> Lennox,
>>>
>>> Here's (attached) the simplest kml that I've been able to make that
>>> doesn't work. Any ideas?
>>>
>>> Bryan
>>>
>>> Bryan Keith wrote:
>>>> Lennox,
>>>>
>>>> I'm attaching the polygon as a shapefile. I'm not ccing the list since
>>>> the list doesn't like the attachment. I can also send you the kml, but
>>>> it's larger than the shapefile.
>>>>
>>>> The polygon does have holes, but I also have other large complicated
>>>> polygons with holes that do display correctly.
>>>>
>>>> Bryan
>>>>
>>>> Lennox Antoine wrote:
>>>>> Can you supply one of the problematic polygon coordlist? I haven't run
>>> into
>>>>> any problems with complex polygons (without holes), so I don't know
>>> what
>>>>> could be the problem off hand without trying it.
>>>>>
>>>>> -Lennox
>>>>>
>>>>> On 4/8/07, Bryan Keith <bryan at geomega.com> wrote:
>>>>>> Lennox,
>>>>>>
>>>>>> I got your suggestion to work for polygons that weren't giving me
>>>>>> problems, but it did not change anything for the problematic polygons.
>>>>>>
>>>>>> Bryan
>>>>>>
>>>>>> Lennox Antoine wrote:
>>>>>>> You are probably experiencing a tesselation problem. Here is a
>>> polygon
>>>>>>> template I normally use for filling complex polygons in GE. Note the
>>>>>>> tesselation attribute, and how to use it.
>>>>>>>
>>>>>>> <Polygon>
>>>>>>> <extrude>0</extrude>
>>>>>>> <altitudeMode>clampToGround</altitudeMode>
>>>>>>> <tessellate>1</tessellate>
>>>>>>> <outerBoundaryIs>
>>>>>>> <LinearRing><coordinates></coordinates></LinearRing>
>>>>>>> </outerBoundaryIs>
>>>>>>> </Polygon>
>>>>>>>
>>>>>>> <Style>
>>>>>>> <LineStyle>
>>>>>>> <color></color>
>>>>>>> <width></width>
>>>>>>> </LineStyle>
>>>>>>> <PolyStyle>
>>>>>>> <fill>1</fill>
>>>>>>> <color></color>
>>>>>>> </PolyStyle>
>>>>>>> </Style>
>>>>>>>
>>>>>>> -Lennox
>>>>>>>
>>>>>>> On 4/8/07, Bryan Keith <bryan at geomega.com> wrote:
>>>>>>>> Hello,
>>>>>>>>
>>>>>>>> I have a shapefile with a single record, a polygon shape. I tried
>>>>>>>> attaching the shapefile to this e-mail, but the server didn't like
>>> it.
>>>>>>>> I'll gladly e-mail the shapefile to anyone who's willing to look
>>> into
>>>>>>>> this. It's ~722KB. I can convert the shapefile to kml like this:
>>>>>>>>
>>>>>>>> ogr2ogr -f kml testblm_py.kml testblm_py.shp
>>>>>>>>
>>>>>>>> When I look at the kml in Google Earth, it looks fine. The outline
>>> of
>>>>>>>> the shapefile shows up as a red line which, I guess, is the default
>>> for
>>>>>>>> ogr2ogr kml output. However, I want to see filled polygons so I
>>>>>> replace
>>>>>>>> part of the "style" line in the kml like this:
>>>>>>>>
>>>>>>>> cat testblm_py.kml | sed
>>> "s/<fill>0<\/fill>/<color>ff37d9f0<\/color>/"
>>>>>>>> testblmfill_py.kml
>>>>>>>>
>>>>>>>> The shaded area does not show up correctly in Google Earth. It
>>> shows
>>>>>> up
>>>>>>>> as lots of vertical striped areas within the polygon.
>>>>>>>>
>>>>>>>> My actual workflow is a fair bit different from what I've described
>>>>>>>> here, but I've tried to boil the problem down to a simple
>>> example. I
>>>>>>>> realize, however, that this polygon is not simple. I'm processing
>>> over
>>>>>>>> 10000 land ownership polygons in Utah, and I'm only having a problem
>>>>>>>> with a few of the big, complicated polygons.
>>>>>>>>
>>>>>>>> I'm wondering if it might be a problem with the line length in the
>>> kml,
>>>>>>>> but I'm not sure. I'm still doing some testing. Any ideas are
>>>>>>>> appreciated.
>>>>>>>>
>>>>>>>> Bryan
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> FWTools mailing list
>>>>>>>> FWTools at lists.maptools.org
>>>>>>>> http://lists.maptools.org/mailman/listinfo/fwtools
>>>>>>>> http://fwtools.maptools.org/
>>>>>>>>
> _______________________________________________
> FWTools mailing list
> FWTools at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/fwtools
> http://fwtools.maptools.org/
>
>
More information about the FWTools
mailing list