bjornharrtell / jsts

JavaScript Topology Suite
http://bjornharrtell.github.io/jsts/
Other
1.49k stars 232 forks source link

WKTParser-Error (MultiPoint / MultiPolygon with Empty-Component) #499

Closed motto76 closed 1 year ago

motto76 commented 1 year ago

We try to create multi-geometries with EMPTY components via the WKTParser. For MultiLineStrings this works, for points and polygons it leads to an error.

Here are some tests that show the problem:

/* eslint-disable @typescript-eslint/no-explicit-any */
import GeometryFactory from 'jsts/org/locationtech/jts/geom/GeometryFactory'
import PrecisionModel from 'jsts/org/locationtech/jts/geom/PrecisionModel'
import WKTReader from 'jsts/org/locationtech/jts/io/WKTReader'

const createGeometryWithGeometryFactory = (wkt: string, digits: number): jsts.geom.Geometry => {
  const gf = createGeometryFactory(digits)
  const reader = new WKTReader(gf as jsts.geom.GeometryFactory)
  return reader.read(wkt) as jsts.geom.Geometry
}

const createGeometryFactory = (digits: number): jsts.geom.GeometryFactory => {
  const scale = Math.pow(10, digits)
  const pm = new PrecisionModel(scale)
  return new GeometryFactory(pm)
}

it('createMultiPoint', () => {
  const gf = createGeometryFactory(2)
  const geom = createGeometryWithGeometryFactory('MULTIPOINT ((180 270), (330 270), (330 150), (180 150))', 2)
})

it('createMultiPointWithEmpty', () => {
  const gf = createGeometryFactory(2)
  const geom = createGeometryWithGeometryFactory('MULTIPOINT ((180 270), (330 270), (330 150), (180 150), EMPTY)', 2)
})

it('createMultiLineString', () => {
  const gf = createGeometryFactory(2)
  const geom = createGeometryWithGeometryFactory(
    'MULTILINESTRING ((100 300, 200 300), (200 300, 100 200), (100 200, 200 200))',
    2
  )
})

it('createMultiLineStringWithEmpty', () => {
  const gf = createGeometryFactory(2)
  const geom = createGeometryWithGeometryFactory(
    'MULTILINESTRING ((100 300, 200 300), (200 300, 100 200), (100 200, 200 200), EMPTY)',
    2
  )
})

it('createMultiPolygon', () => {
  const gf = createGeometryFactory(2)
  const geom = createGeometryWithGeometryFactory(
    'MULTIPOLYGON (((200 270, 260 270, 260 210, 200 210, 200 270)),((270 200, 330 200, 330 150, 270 150, 270 200)))',
    2
  )
})

it('createMultiPolygonWithEmpty', () => {
  const gf = createGeometryFactory(2)
  const geom = createGeometryWithGeometryFactory(
    'MULTIPOLYGON (((200 270, 260 270, 260 210, 200 210, 200 270)),((270 200, 330 200, 330 150, 270 150, 270 200)), EMPTY)',
    2
  )
})

grafik

The "createMultiPointWithEmpty" and "createMultiPolygonWithEmpty" tests fail with the following error messages: grafik grafik

Is there a workaround or solution to this problem? Thanks

bjornharrtell commented 1 year ago

Looks like a bug. Probably no way around other than fixing it.