Code Monkey home page Code Monkey logo

dart_jts's Introduction

Dart JTS

pub package Build Status

dart_jts is an ongoing effort to port the Java Topology Suite to the dart programming language and make it available to its mobile, dektop and web environments.

dart_jts is derivative work of JTS Topology Suite.

This is currently developed by HydroloGIS.

Contributions are very welcome. Please, if you port some code over from JTS java, also bring in the testcases. Without them we will not accept the pull requests. Thank you!

Project License

Copyright (C) 2020 HydroloGIS

The project is distributed under the Eclipse Distribution License - v 1.0, the same as the JTS project itself.

dart_jts's People

Contributors

airof98 avatar badger3512 avatar hebersousa avatar iulian0512 avatar iwishiwasaneagle avatar jetpeter avatar mohammedx6 avatar moovida avatar samyarous avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dart_jts's Issues

create buffer for line string

I am trying to create a buffer for a LINESTRING

LINESTRING (35.8027978006563146 31.8588533106116252, 35.8105578052783642 31.8586604663966249, 35.8105417762212284 31.8520311786293853, 35.8027978006563146 31.8588533106116252)

Screen Shot 2021-11-04 at 12 51 53 PM

What i do:
JTS.BufferParameters bufParams = JTS. BufferParameters();
JTS.Polygon bufferd=JTS.BufferOp.bufferOpWithParams(geometry, .000001, bufParams);

but the buffer result is wrong
POLYGON ((35.8027978006563146 31.8588533106116252, 35.8027978254996881 31.8588543103029807, 35.8105578301217378 31.8586614660879803, 35.8105580219384336 31.8586614426437329, 35.8105582056643286 31.8586613827432181, 35.8105583744385001 31.8586612886233205, 35.8105585219583702 31.8586611637987822, 35.8105586427150584 31.8586610129309626, 35.8105587321991194 31.8586608416537587, 35.8105587870689206 31.8586606563632238, 35.8105588052754413 31.8586604639787154, 35.8105427762183055 31.8520311762114758, 35.8105427575970623 31.8520309865318154, 35.810542703327215 31.8520308038301252, 35.8105426153801361 31.8520306347430626, 35.8105424969504966 31.8520304854127403, 35.8105423523402848 31.8520303612635942, 35.810542186802472 31.8520302668053645, 35.8105420063502464 31.8520302054692586, 35.8105418175385566 31.8520301794833109, 35.8105416272260086 31.8520301897914706, 35.8105414423257287 31.8520302360192886, 35.8105412695542498 31.8520303164875358, 35.8105411151875046 31.8520304282731921, 35.8027971396225908 31.85885256

Screen Shot 2021-11-04 at 12 53 37 PM

I want the buffer like this way:

single-sided-buffer-right

polygon union ?

Thanks for the library.
How I can do polygon union using this library?

polygon intersection?

Thank you for providing this library. I need to calculate the intersection length of polylines and polygons, but it shows "Not implemented yet". How can I implement it? I am looking forward to your reply.

Problem comparing GeometryCollections

const String WKT_GC = 'GEOMETRYCOLLECTION (POLYGON ((100 200, 200 200, 200 100, 100 100, 100 200)), LINESTRING (150 250, 250 250))';
Reading the geometry above using rdr below fails with

Invalid argument(s): Operation does not support GeometryCollection arguments
package:dart_jts/src/com/hydrologis/dart_jts/geom/geometry.dart 1687:7 Geometry.checkNotGeometryCollection
package:dart_jts/src/com/hydrologis/dart_jts/geom/geometry.dart 913:5 Geometry.relate
package:dart_jts/src/com/hydrologis/dart_jts/geom/geometry.dart 967:12 Geometry.equalsTopo
package:dart_jts/src/com/hydrologis/dart_jts/geom/geometry.dart 937:12 Geometry.equals
test\geometry_test.dart 183:25 main..

final geomFactory = GeometryFactory.withCoordinateSequenceFactory(PackedCoordinateSequenceFactory.withType(PackedCoordinateSequenceFactory.DOUBLE));
final rdr = WKTReader.withFactory(geomFactory);
final actualGeom = rdr.read(WKT_GC);

Planargraph, LineMerge, LineSequence

Hi there! I'm looking to help extend your port of JTS to dart by adding a few other classes that haven't been brought over yet. Namely, I'm interested in the LineMerge and LineSequence operations, which have a few dependencies on other unported classes.

I have a few questions after getting started:

  1. It looks like geomgraph has been ported but not yet planargraph, which is used by LineMerge. I assume these graph types are inherently different under the hood, but before I spend time on moving planargraph over, I wanted to make sure there wasn't some consolidation to use only geomgraph and desire not to port planargraph?

  2. Some class names are the same between geomgraph and planargraph, namely DirectedEdge, Node, etc., among a few others. Since dart_jts is globally namespaced within the library, there are some conflicts here in the naming. Have you thought about how to namespace conflicting types? 

  • One option could be to just create new class names and break the exact naming of the java->dart port (eg, PlanarDirectEdge). 
  • Another option would be to deprecate using part/part-of entirely and directly import necessary imports as needed, but this would be a bigger refactor of the library. Dart.dev recommends this approach (and not using part/part of): https://dart.dev/guides/libraries/create-library-packages

Just wanted to get your thoughts before I open a contribution PR.

build issues with intl and collection packages

first issue is with intl:

flutter pub get
Resolving dependencies... (1.1s)
Note: intl is pinned to version 0.18.1 by flutter_localizations from the flutter SDK.
See https://dart.dev/go/sdk-version-pinning for details.
Because dart_jts 0.2.3+2 depends on intl >=0.16.1 <=0.18.0 and no versions of dart_jts match >0.2.3+2 <0.3.0, dart_jts ^0.2.3+2 requires intl >=0.16.1 <=0.18.0.

0.18.1 is greater than whats in dart_jts pubspec

then

flutter pub get
Resolving dependencies... (1.1s)
Note: collection is pinned to version 1.17.2 by flutter_localizations from the flutter SDK.
See https://dart.dev/go/sdk-version-pinning for details.

Because every version of flutter_localizations from sdk depends on collection 1.17.2 and dart_jts 0.2.3+2 depends on collection >=1.14.13 <=1.17.1, flutter_localizations from sdk is incompatible with
dart_jts 0.2.3+2.
And because no versions of dart_jts match >0.2.3+2 <0.3.0, flutter_localizations from sdk is incompatible with dart_jts ^0.2.3+2.

again with collection

i suggest you remove the upper version constraint in pubspec.yaml

dependencies:
intl: '>=0.16.1'
collection: '>=1.14.13'

Geometry.buffer() with zero distance results

A zero distance buffer call on a Polygon with a self-intersection gives different results from an identical case in the Java library. For example, the following Junit case for the Java API runs successfully:
`public void testInvalidPolygon(){

  try {
      WKTReader rdr = new WKTReader();
      Geometry geom = rdr.read("POLYGON ((21.32686 47.78723, 21.31486 47.81023, "
              + "21.32786 47.81123, 21.33986 47.80223, 21.32586 47.82723, "
              + "21.32786 47.82323, 21.33886 47.82623, 21.34186 47.82123, "
              + "21.40686 47.81723, 21.32686 47.78723))");  //Self-Intersecting
      IsValidOp op = new IsValidOp(geom);
      if(!op.isValid()){
          System.out.println(op.getValidationError().getMessage());
          Geometry geomFixed = geom.buffer(0.0);
          Geometry expected = rdr.read("POLYGON ((21.32686 47.78723, 21.31486 47.81023, "
                  + "21.32786 47.81123, 21.33986 47.80223, 21.328068201892744 47.823286782334385, "
                  + "21.33886 47.82623, 21.34186 47.82123, 21.40686 47.81723, 21.32686 47.78723))");
          checkEqual(geomFixed,expected);
      }
  } catch (ParseException ex) {
      Logger.getLogger(InvalidPolygonTest.class.getName()).log(Level.SEVERE, null, ex);
  }

}`

while the following equivalent dart test fails:

`test('testInvalidPolygon', () {

WKTReader rdr = WKTReader();
Geometry? geom = rdr.read(
    'POLYGON ((21.32686 47.78723, 21.31486 47.81023,21.32786 47.81123, '
        '21.33986 47.80223, 21.32586 47.82723,21.32786 47.82323, 21.33886 47.82623, '
        '21.34186 47.82123,21.40686 47.81723, 21.32686 47.78723))');   //Self-Intersecting
IsValidOp op = IsValidOp(geom!);
if (!op.isValid()) {
  print(op.getValidationError()!.getMessage());
  Geometry geomFixed = geom.buffer(0.0);
  Geometry? expected = rdr.read('POLYGON ((21.32686 47.78723, 21.31486 47.81023, ' +
      '21.32786 47.81123, 21.33986 47.80223, 21.328068201892744 47.823286782334385, ' +
      '21.33886 47.82623, 21.34186 47.82123, 21.40686 47.81723, 21.32686 47.78723))');
  checkEqualMsg('Geometries are not equal',expected!,geomFixed);
}

});`

The dart case produces the following output:

Self-intersection
FAIL - Geometries are not equal: Expected = POLYGON ((21.3148599999999995 47.8102299999999971, 21.3278600000000012 47.8112300000000019, 21.3398600000000016 47.8022300000000016, 21.3280682018927444 47.8232867823343852, 21.3388600000000004 47.8262300000000025, 21.3418600000000005 47.8212299999999999, 21.4068600000000018 47.8172300000000021, 21.32686 47.787230000000001, 21.3148599999999995 47.8102299999999971)) -- Actual = POLYGON ((21.3258599999999987 47.8272300000000001, 21.3280682018927444 47.8232867823343852, 21.3278600000000012 47.8232300000000023, 21.3258599999999987 47.8272300000000001))
package:matcher expect
test/invalid_polygon_test.dart 12:5 main.checkEqualMsg
test/invalid_polygon_test.dart 28:7 main.

Expected:
Actual:

dart_jts build issues with flutter 3.0

Because dart_jts 0.2.1 depends on collection >=1.14.13 <=1.15.0 and no versions of dart_jts match >0.2.1 <0.3.0, dart_jts ^0.2.1 requires collection >=1.14.13 <=1.15.0.
And because every version of flutter_test from sdk depends on collection 1.16.0, dart_jts ^0.2.1 is incompatible with flutter_test from sdk.

Question about geometry CoordinateSequence dimension

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);
});

null safety?

Is this lib planned to migrate to null-safety?

How to check if a polygon edge crosses another edge within the same polygon

Hi,

In my code I am trying to check whether a polygon is "valid" or not. A valid polygon in my case is one where none of the edges within the geometry intersect. For example:

  • Valid: [(0,0),(0,1),(1,1),(1,0)]

  • Invalid: [[(0,0),(0,1),(0.5,-1),(1,1),(1,0)]]

How would I do this? So far crosses and intersect don't work for a whole polygon. Would I have to iterate over each edge?

Many thanks in advance!

IsValidOp fails to detect a linear ring self-intersection

The IsValidOp class fails to detect the self-intersections existing in the following LinearRing.

LINEARRING (7 8, 3 8, 1 5, 1 6, 3 3, 7 3, 9 6, 9 5, 7 8)

The following test routine illustrates the issue:

test('linearringintersection_test',(){
    final wkt = 'LINEARRING (7 8, 3 8, 1 5, 1 6, 3 3, 7 3, 9 6, 9 5, 7 8)';
    final ring = WKTReader().read(wkt);
    IsValidOp op = IsValidOp(ring!);
    expect(op.validErr != null,true);
  });

The expected result is:

Ring Self-intersection at or near point (1.3333333333333335, 5.5)

An image of the geometry is shown below.

image-4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.