moovida / dart_jts

An effort to port some of the Java Topology Suite to dart
Other
26 stars 19 forks source link

Question about geometry CoordinateSequence dimension #5

Closed bettdouglas closed 3 years ago

bettdouglas commented 3 years ago

Hi, I'm trying to port some GeometryTransformer code from java jts here.

However, some test case fails to pass concerning line.getCoordinateSequence().

Am I missing something or

test('preserve dimension 2d', () {
  final gf = GeometryFactory.defaultPrecision();

  final line=  gf.createLineString([
    Coordinate(1,2),
    Coordinate(3,4),
  ]);
  expect(line.getCoordinateSequence().getDimension(), 2); //this returns 3 but passes in the original jts code. it should be 2
  final densifiedLine = densify(line, 0.1) as LineString;
  expect(densifiedLine.getCoordinateSequence().getDimension(), 2);
});
moovida commented 3 years ago

Hi @bettdouglas , is there an existing JTS test to reproduce it? I can't find it and would rather use the original jts testcases where possible.

bettdouglas commented 3 years ago

Hi, sorry I did not. The code is here https://github.com/locationtech/jts/blob/78a4b5e9ab1219fcedba8790142dc4b1ee12976f/modules/core/src/test/java/org/locationtech/jts/densify/DensifierTest.java#L76

moovida commented 3 years ago

I just created a testcase with your example in jts:

        GeometryFactory gf = new GeometryFactory();

        Coordinate[] coordinates = new Coordinate[] {
          new Coordinate(1.0,2.0),
          new Coordinate(3.0,4.0)
        };
        LineString line=  gf.createLineString(coordinates);
        int dimension = line.getCoordinateSequence().getDimension();
        System.out.println(dimension);

This returns 3, same as the dart version.

moovida commented 3 years ago

@bettdouglas , the example you refer to uses: CoordinateXY, not Coordinate Do the same with dart_jts, and the result is the same. Closing this here.

bettdouglas commented 3 years ago

Ok. So when one is sure there are two coordinates use CoordinateXY instead of Coordinate? I don't know much Java, just basics

bettdouglas commented 3 years ago

Just tried that. Same issue here

test('preserve dimension 2d', () {
  final gf = GeometryFactory.defaultPrecision();

  final line=  gf.createLineString([
    CoordinateXY.fromXY(1,2),
    CoordinateXY.fromXY(3,4),
  ]);
  expect(line.getCoordinateSequence().getDimension(), 2);
  final densifiedLine = densify(line, 0.1) as LineString;
  expect(densifiedLine.getCoordinateSequence().getDimension(), 2);
});
moovida commented 3 years ago

Tried this (where you signalled the error):

      final gf = GeometryFactory.defaultPrecision();

      final line = gf.createLineString([
        CoordinateXY.fromXY(1, 2),
        CoordinateXY.fromXY(3, 4),
      ]);
      var coordinateSequence = line.getCoordinateSequence();
      var dimension = coordinateSequence.getDimension();
      expect(dimension, 2);

And this passes properly. If you have an issue later, then that is probably in your code somewhere. Make sure you use the right coordinate class.

Anyways, it really depends on you what you need to use. The most used is Coordinate, even if it has a 3rd dimension, which is mostly not used.

bettdouglas commented 3 years ago

Just tried that. Same issue here

test('preserve dimension 2d', () {
  final gf = GeometryFactory.defaultPrecision();

  final line=  gf.createLineString([
    CoordinateXY.fromXY(1,2),
    CoordinateXY.fromXY(3,4),
  ]);
  expect(line.getCoordinateSequence().getDimension(), 2);
  final densifiedLine = densify(line, 0.1) as LineString;
  expect(densifiedLine.getCoordinateSequence().getDimension(), 2);
});

Okay, I wasn't keen enough. The test was failing on last test

bettdouglas commented 3 years ago

@moovida thanks for this

bettdouglas commented 3 years ago

@moovida I've tried finding out where the bug causing the dimension preservation test case to fail, but I cannot figure out where it is.

If you have some time and wanna assist, look at it here https://github.com/bettdouglas/dart_jts.git

Also I couldn't find any Class tests for GeometryTransformer, the way there is for Densifier. Could you point me to it if you find it?