2

When I try to draw a "perforated" polygon using GeoJSON.readFeatures() the "solid/void" relationship is drawn correctly, the void parts don't have any fill color. See the example, GeoJSON included: https://codesandbox.io/s/magical-beaver-0fzuf

And here is the result, which is the desired one:

enter image description here

But when I use the WKB Geometry that's coming from PostGIS and creating the feature with:

polygonWkbGeometryFromPostGis.coordinates.forEach((coords) => {
        const feature = new Feature({
          geometry: new Polygon([coords]);
        });
      });

I get all the voids filled with color, which is wrong:

wrong

Just in case, the WKB geometry (link to this example's text representation) is being displayed correctly in the DB client as well:

enter image description here

In both examples I'm using OpenLayers 6.5.0 and the exact same ol/style.

What's causing the issue?

3
  • You are creating multiple overlapping Polygon features from the coordinates of each ring. For a single polygon with holes use new Polygon(polygonWkbGeometryFromPostGis.coordinates)
    – Mike
    Jun 28 at 22:20
  • Or you could readFeatures from the WKT string in the same way as you readFeatures from the GeoJSON codesandbox.io/s/sleepy-williams-wv3gh
    – Mike
    Jun 28 at 22:25
  • @Mike Can you post these as an answer so that I can accept? Thanks a lot! Jun 28 at 22:30
2

You are creating multiple overlapping Polygon features from the coordinates of each ring. For a single polygon with holes use

new Feature({
  geometry: new Polygon(polygonWkbGeometryFromPostGis.coordinates)
})

Or you could readFeatures from the WKT string in the same way as you readFeatures from the GeoJSON https://codesandbox.io/s/sleepy-williams-wv3gh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.