union KML files with multigeometry problem

50 views
Skip to first unread message

Leonard Carter

unread,
Oct 25, 2019, 3:04:08 PM10/25/19
to JSTS devs
Greetings,

I am trying to union KML files with multigeometry in one or more files. The files represent zip code areas, and some have sections that are separated from the main body, resulting in more than one Polygon. As an example, here is 21108.kml:

      <MultiGeometry>
        <extrude>0</extrude>
        <tessellate>1</tessellate>
        <altitudeMode>clampToGround</altitudeMode>
        <Polygon>
          <extrude>0</extrude>
          <tessellate>1</tessellate>
          <altitudeMode>clampToGround</altitudeMode>
          <outerBoundaryIs>
            <LinearRing>
              <coordinates>-76.636917,39.123636,0.0 ... -76.635586,39.124022,0.0 -76.636917,39.123636,0.0</coordinates>
            </LinearRing>
          </outerBoundaryIs>
        </Polygon>
        <Polygon>
          <extrude>0</extrude>
          <tessellate>1</tessellate>
          <altitudeMode>clampToGround</altitudeMode>
          <outerBoundaryIs>
            <LinearRing>
              <coordinates>-76.662098,39.049158,0.0 ... -76.662098,39.049158,0.0</coordinates>
            </LinearRing>
          </outerBoundaryIs>
          <innerBoundaryIs>
            <LinearRing>
              <coordinates>-76.623378,39.122061,0.0 ... -76.623378,39.122061,0.0</coordinates>
            </LinearRing>
          </innerBoundaryIs>
        </Polygon>
      </MultiGeometry>


I have omitted most of the coordinates for brevity. When I bring this into my code, the union operation only grabs the first instance of Polygon and ignores the second. If I remove the first Polygon from the file, the code does handle the inner boundary properly, though. If the region has no zips with multiple polygons, the code works flawlessly.

Here's my code for the union:

var geometryFactory = new jsts.geom.GeometryFactory();
objArray[polygonindex] = geometryFactory.createPolygon(geometryFactory.createLinearRing(googleMaps2JSTS(doc[polygonindex].gpolygons[0].getPath())));


Can someone assist me? I'm sure I just don't know the right syntax for this.

Thanks!
Jamie

Leonard Carter

unread,
Oct 25, 2019, 3:08:09 PM10/25/19
to JSTS devs
I hit "post" before adding all the code, sorry about that.

This code is below the previous code, outside of the loop that builds the collection of zip codes.

var JSTSpolyUnion = objArray[0];
for (unionindex = 0; unionindex < objArray.length-1; unionindex++) {
console.log(unionindex);
JSTSpolyUnion = JSTSpolyUnion.union(objArray[unionindex+1]);
}

var outputPath = jsts2googleMaps(JSTSpolyUnion);

var unionPoly = new google.maps.Polygon({
map: map,
paths: outputPath,
strokeColor: '#0000FF',
strokeOpacity: 0.9,
strokeWeight: 2,
fillColor: '#0000FF',
fillOpacity: 0.4
});



Reply all
Reply to author
Forward
0 new messages