Package com.vividsolutions.jts.io

Examples of com.vividsolutions.jts.io.WKTReader


        assertEquals(diff, diff2);
    }

    @Test
    public void testCanApply() throws Exception {
        Geometry oldGeom = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
        Geometry newGeom = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 35, 45 30, 40 40),(20 35, 45 20, 30 15, 10 10, 10 30, 20 35),(10 10, 20 20, 35 30))");
        LCSGeometryDiffImpl diff = new LCSGeometryDiffImpl(Optional.of(oldGeom),
                Optional.of(newGeom));
        Geometry oldGeomModified = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 41),(20 35, 45 10, 30 5, 10 30, 20 35))");
        assertTrue(diff.canBeAppliedOn(Optional.of(oldGeomModified)));
        Geometry oldGeomModified2 = new WKTReader().read("MULTILINESTRING ((40 40, 10 10))");
        assertFalse(diff.canBeAppliedOn(Optional.of(oldGeomModified2)));
    }


        assertFalse(diff.canBeAppliedOn(Optional.of(oldGeomModified2)));
    }

    @Test
    public void testConflict() throws Exception {
        Geometry oldGeom = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
        Geometry newGeom = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 45),(20 35, 45 10, 20 35))");
        GeometryAttributeDiff diff = new GeometryAttributeDiff(Optional.of(oldGeom),
                Optional.of(newGeom));
        Geometry newGeom2 = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 45, 41 33, 25 25),(20 35, 45 10, 30 5, 10 30, 20 35))");
        GeometryAttributeDiff diff2 = new GeometryAttributeDiff(Optional.of(oldGeom),
                Optional.of(newGeom2));
        assertTrue(diff.conflicts(diff2));
    }

        assertTrue(diff.conflicts(diff2));
    }

    @Test
    public void testConflictEditedSamePoint() throws Exception {
        Geometry oldGeom = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
        Geometry newGeom = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 45, 48 32, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
        GeometryAttributeDiff diff = new GeometryAttributeDiff(Optional.of(oldGeom),
                Optional.of(newGeom));
        Geometry newGeom2 = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 45, 41 33, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
        GeometryAttributeDiff diff2 = new GeometryAttributeDiff(Optional.of(oldGeom),
                Optional.of(newGeom2));
        assertTrue(diff.conflicts(diff2));
    }

        assertTrue(diff.conflicts(diff2));
    }

    @Test
    public void testNoConflict() throws Exception {
        Geometry oldGeom = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
        Geometry newGeom = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 45, 45 35, 30 30),(20 35, 45 10, 30 5, 10 30, 20 35))");
        GeometryAttributeDiff diff = new GeometryAttributeDiff(Optional.of(oldGeom),
                Optional.of(newGeom));
        Geometry newGeom2 = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 31 6, 10 30, 20 35))");
        GeometryAttributeDiff diff2 = new GeometryAttributeDiff(Optional.of(oldGeom),
                Optional.of(newGeom2));
        assertFalse(diff.conflicts(diff2));
        Optional<?> merged = diff2.applyOn(Optional.of(newGeom));

                mergedGeom.toText());
    }

    @Test
    public void testNoConflictAddingPoints() throws Exception {
        Geometry oldGeom = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
        Geometry newGeom = new WKTReader()
                .read("MULTILINESTRING ((40 40, 10 10, 20 45, 45 30, 30 30),(20 35, 45 10, 30 5, 10 30, 20 35))");
        GeometryAttributeDiff diff = new GeometryAttributeDiff(Optional.of(oldGeom),
                Optional.of(newGeom));
        Geometry newGeom2 = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 31 6, 10 30, 20 35))");
        GeometryAttributeDiff diff2 = new GeometryAttributeDiff(Optional.of(oldGeom),
                Optional.of(newGeom2));
        assertFalse(diff.conflicts(diff2));
        Optional<?> merged = diff2.applyOn(Optional.of(newGeom));

                mergedGeom.toText());
    }

    @Test
    public void testNoConflictRemovingPoints() throws Exception {
        Geometry oldGeom = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
        Geometry newGeom = new WKTReader()
                .read("MULTILINESTRING ((40 40, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
        GeometryAttributeDiff diff = new GeometryAttributeDiff(Optional.of(oldGeom),
                Optional.of(newGeom));
        Geometry newGeom2 = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 31 6, 10 30, 20 35))");
        GeometryAttributeDiff diff2 = new GeometryAttributeDiff(Optional.of(oldGeom),
                Optional.of(newGeom2));
        assertFalse(diff.conflicts(diff2));
        Optional<?> merged = diff2.applyOn(Optional.of(newGeom));

                mergedGeom.toText());
    }

    @Test
    public void testNoConflictIfSameDiff() throws Exception {
        Geometry oldGeom = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
        Geometry newGeom = new WKTReader()
                .read("MULTILINESTRING ((40 40, 20 45, 45 35, 30 30),(20 35, 45 10, 30 5, 10 30, 20 35))");
        GeometryAttributeDiff diff = new GeometryAttributeDiff(Optional.of(oldGeom),
                Optional.of(newGeom));
        GeometryAttributeDiff diff2 = new GeometryAttributeDiff(Optional.of(oldGeom),
                Optional.of(newGeom));

public class IsValidTester {

  public IsValidTester() {
  }
  public static void main(String[] args) throws Exception {
    WKTReader reader = new WKTReader(new GeometryFactory());
    Geometry g = reader.read("GEOMETRYCOLLECTION (POINT (110 300), POINT (100 110), POINT (130 210), POINT (150 210), POINT (150 180), POINT (130 170), POINT (140 190), POINT (130 200), LINESTRING (240 50, 210 120, 270 80, 250 140, 330 70, 300 160, 340 130, 340 130), POLYGON ((210 340, 220 260, 150 270, 230 220, 230 140, 270 210, 360 240, 260 250, 260 280, 240 270, 210 340), (230 270, 230 250, 200 250, 240 220, 240 190, 260 220, 290 230, 250 230, 230 270)))");
    IsValidOp op = new IsValidOp(g);
    if (!op.isValid()) {
      System.out.println(op.getValidationError().getMessage());
    }
    else {

            setVisible(false);
    }

    Geometry parseGeometry(JTextComponent txt, Color clr) {
        try {
            WKTReader rdr =
                new WKTReader(
                    new GeometryFactory(JTSTestBuilder.model().getPrecisionModel(), 0));
            Geometry g = rdr.read(txt.getText());
            txtError.setText("");
            return g;
        } catch (Exception ex) {
            txtError.setText(ex.getMessage());
            txtError.setForeground(clr);

import com.vividsolutions.jts.io.WKTReader;
import com.vividsolutions.jts.io.gml2.GMLWriter;

public class GeometryAdapter extends XmlAdapter<String,Geometry> {
    public Geometry unmarshal(String val) throws Exception {
        return new WKTReader(GeometryUtils.getGeometryFactory()).read(val);
    }

TOP

Related Classes of com.vividsolutions.jts.io.WKTReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.