示例#1
0
def makeArea(gridLoc, pointList, refname=None):
    " Make a Reference Area with a unique ReferenceID"
    from com.vividsolutions.jts.geom import GeometryFactory, LinearRing, Coordinate, Polygon
    from com.raytheon.uf.common.dataplugin.gfe.reference import ReferenceData
    CoordinateType = ReferenceData.CoordinateType
    geomFactory = GeometryFactory()
    import jep
    size = len(pointList)
    if pointList[0] != pointList[size - 1]:  # closing the loop
        pointList.append(pointList[0])
    pointArray = jep.jarray(len(pointList), Coordinate)
    for i in range(len(pointList)):
        pointArray[i] = pointList[i]
    lr = geomFactory.createLinearRing(pointArray)
    poly = geomFactory.createPolygon(lr, jep.jarray(0, LinearRing))
    polyArray = jep.jarray(1, Polygon)
    polyArray[0] = poly
    region = geomFactory.createMultiPolygon(polyArray)
    if refname is None:
        refname = "Ref" + getTime()
    refId = ReferenceID(refname)
    refData = ReferenceData(gridLoc, refId, region, CoordinateType.LATLON)
    # randerso: I don't think this is necessary
    # refData.convertToAWIPS()
    return refData
示例#2
0
    def append_to_errors(self, errorsList, check):
        """Clean errors list from duplicate errors and ids that must be
           ignored
        """
        if errorsList[0][0] == "":
            #osmId == "", this tool doesn't give id of OSM objects
            check.errors = [Error(check, e) for e in errorsList]
        else:
            if check.ignoreIds != []:
                #remove OSM objects that the user wants to ignore
                check.errors = [Error(check, e) for e in errorsList if e[0] not in check.ignoreIds]

                #remove duplicate ids
                #check.errors = dict((e.osmId, e) for e in check.errors).values()
            else:
                #copy all errors and remove duplicate ids
                #check.errors = dict((e[0], Error(e)) for e in errorsList).values()
                check.errors = [Error(check, e) for e in errorsList]

            #Remove from the list of errors those that have been reviewed yet
            #while clicking the "Next" button
            check.errors = [e for e in check.errors if e.osmId not in check.reviewedIds]

        #print "\n- errors of selected check in current zone:", [e.osmId for e in check.errors]

        #Randomize the errors so that different users don't start
        #correcting the same errors
        Collections.shuffle(check.errors)

        #Filter errors in favourite zone
        if self.app.favouriteZoneStatus and self.app.favZone.zType != "rectangle":
            #not rectangular favourite area, use jts
            from com.vividsolutions.jts.geom import Coordinate, GeometryFactory
            polygon = self.app.favZone.wktGeom
            errorsInPolygon = []
            for error in check.errors:
                (lat, lon) = error.coords
                point = GeometryFactory().createPoint(Coordinate(lon, lat))
                if polygon.contains(point):
                    if error not in errorsInPolygon:
                        errorsInPolygon.append(error)
            check.errors = errorsInPolygon

        #Apply limits from preferences
        #max number of errors
        limits = []
        if self.app.maxErrorsNumber != "":
            limits.append(self.app.maxErrorsNumber)
        try:
            if self.tool.prefs["limit"] != "":
                limits.append(int(self.tool.prefs["limit"]))
        except:
            pass
        if limits != []:
            check.errors = check.errors[:min(limits)]

        #Reset index of current error
        check.currentErrorIndex = -1
        check.toDo = len(check.errors)
示例#3
0
 def getEnvelope(self):
     env = None
     jenv = self.jobj.getEnvelope()
     if jenv:
         import shapely
         from com.vividsolutions.jts.geom import GeometryFactory
         env = shapely.wkt.loads(
             GeometryFactory().toGeometry(jenv).toText())
     return env
示例#4
0
def createOTPGraphTables():
    otp = OtpsEntryPoint.fromArgs(
        ["--graphs", "/Users/gijspeters/otp/amsterdam", "--autoScan"])
    router = otp.getRouter()
    req = otp.createRequest()
    req.setDateTime(MONDAY.year, MONDAY.month, MONDAY.day, 12, 0, 0)
    req.setMaxTimeSec(14400)
    req.setOrigin(52.37, 4.889)
    sspt = router.plan(req)
    spt = sspt.spt
    vertices = spt.getVertices().toArray()
    con = Verbinding()
    con.createTable(dbtables.HEDGES)
    con.createTable(dbtables.HVERTICES)

    try:
        monitor = VoortgangRegel(len(vertices), VoortgangRegel.MODUS_NUM,
                                 'Vertices geschreven')
        for vertex in vertices:
            dbvertex = (vertex.getIndex(), vertex.getLabel(),
                        WKBWriter().bytesToHex(WKBWriter().write(
                            GeometryFactory(PrecisionModel(),
                                            4326).createPoint(
                                                vertex.getCoordinate()))))
            sql = "INSERT INTO hvertices (vertex_id, label, geom) VALUES (%d, '%s', '%s')" % dbvertex
            con.exe(sql)
            monitor.plusEen()
        con.commit()
        sql = "SELECT vertex_id, id FROM hvertices"
        hvertices = dict(con.selectAll(sql))
        monitor = VoortgangRegel(len(vertices), VoortgangRegel.MODUS_NUM,
                                 'Edges geschreven van vertices')
        for vertex in vertices:
            edges = vertex.getOutgoing().toArray()
            for edge in edges:
                naam = edge.getName()
                if naam == None:
                    naam = ''
                else:
                    naam = naam.replace("'", "")
                try:
                    geom = WKBWriter().bytesToHex(WKBWriter().write(
                        edge.getGeometry()))
                    hedge = (edge.getId(), naam, hvertices[vertex.getIndex()],
                             hvertices[edge.getToVertex().getIndex()], geom,
                             edge.getDistance())
                    sql = "INSERT INTO hedges (edge_id, label, from_id, to_id, geom, distance) VALUES (%d, '%s', %d, %d, '%s', %f)" % hedge
                except:
                    hedge = (edge.getId(), naam, hvertices[vertex.getIndex()],
                             hvertices.get(edge.getToVertex().getIndex(),
                                           -1), edge.getDistance())
                    sql = "INSERT INTO hedges (edge_id, label, from_id, to_id, distance) VALUES (%d, '%s', %d, %d, %f)" % hedge
                con.exe(sql)
            monitor.plusEen()
        con.commit()
    finally:
        con.sluit()
示例#5
0
 def makeArea(self, pointList, refname=None):
     " Make a Reference Area with a unique ReferenceID"
     from com.vividsolutions.jts.geom import GeometryFactory, LinearRing, Coordinate, Polygon
     from com.raytheon.uf.common.dataplugin.gfe.reference import ReferenceData_CoordinateType as CoordinateType
     geomFactory = GeometryFactory()
     import jep
     size = len(pointList)
     if pointList[0] != pointList[size-1]: # closing the loop
         pointList.append(pointList[0])
     pointArray = jep.jarray(len(pointList), Coordinate)
     for i in range(len(pointList)):
         pointArray[i] = pointList[i]
     lr = geomFactory.createLinearRing(pointArray)
     poly = geomFactory.createPolygon(lr, jep.jarray(0, LinearRing))
     polyArray = jep.jarray(1, Polygon)
     polyArray[0] = poly
     region = geomFactory.createMultiPolygon(polyArray)
     if refname is None:
         refname = "Ref" + getTime()    
     refId = ReferenceID(refname)
     refData = ReferenceData(self.__gridLoc, refId, region, CoordinateType.valueOf("LATLON"))
     # randerso: I don't think this is necessary
     # refData.convertToAWIPS()
     return refData
示例#6
0
 def finalDraw(self, event):
     p = event.coords
     width = abs(p[0].x - p[1].x)
     height = abs(p[0].y - p[1].y)
     geo = GeometryFactory()
     shapeFac = GeometricShapeFactory(geo)
     lowLeft = Coordinate()
     lowLeft.x = min(p[0].x, p[1].x)
     lowLeft.y = min(p[0].y, p[1].y)
     shapeFac.setBase(lowLeft)
     shapeFac.setWidth(width)
     shapeFac.setHeight(height)
     shapeFac.setNumPoints(48)
     pa = shapeFac.createCircle().coordinates
     p.clear()
     for pt in pa:
         p.add(pt)
     panel = event.wc.layerViewPanel
     statMsg = "[" + panel.format(width) + ", " + panel.format(height) + "]"
     event.statusMessage = statMsg
示例#7
0
 def read_area_from_osm_ways(self, mode, dataset):
     """Read way in favourite area editing layer and convert them to
        WKT
     """
     converter = JTSConverter(False)
     lines = [converter.convert(way) for way in dataset.ways]
     polygonizer = Polygonizer()
     polygonizer.add(lines)
     polygons = polygonizer.getPolygons()
     multipolygon = GeometryFactory().createMultiPolygon(list(polygons))
     multipolygonWKT = WKTWriter().write(multipolygon)
     if multipolygonWKT == "MULTIPOLYGON EMPTY":
         if mode == "polygon":
             msg = self.app.strings.getString("empty_ways_polygon_msg")
         else:
             msg = self.app.strings.getString("empty_ways_boundaries_msg")
         JOptionPane.showMessageDialog(self,
             msg,
             self.app.strings.getString("Warning"),
             JOptionPane.WARNING_MESSAGE)
         return
     return multipolygonWKT
示例#8
0
 def setUp(self):
   self.gf = GeometryFactory()
示例#9
0
class GeomTest(unittest.TestCase):

  def setUp(self):
    self.gf = GeometryFactory()

  def testPoint(self):
    p = geom.Point(1,2)
    self.assertEqual('POINT (1 2)', str(p))

  def testPointFromJTS(self):
    p = geom.Point(self.gf.createPoint(Coordinate(1,2)))
    self.assertEqual('POINT (1 2)', str(p))

  def testLineString(self):
    l = geom.LineString((1,2),(3,4))
    self.assertEqual('LINESTRING (1 2, 3 4)', str(l)) 

  def testLineStringFromJTS(self):
    ls = self.gf.createLineString([Coordinate(1,2), Coordinate(3,4)])
    l = geom.LineString(ls)
    self.assertEqual('LINESTRING (1 2, 3 4)', str(l)) 
  
  def testPolygon(self):
    p = geom.Polygon([[1,2],[3,4],[5,6],[1,2]])
    self.assertEqual('POLYGON ((1 2, 3 4, 5 6, 1 2))', str(p)) 

  def testPolygonFromJTS(self):
    poly = self.gf.createPolygon(self.gf.createLinearRing([Coordinate(1,2),Coordinate(3,4), Coordinate(5,6), Coordinate(1,2)]), [])
    p = geom.Polygon(poly)
    self.assertEqual('POLYGON ((1 2, 3 4, 5 6, 1 2))', str(p)) 

  def testMultiPoint(self):
    mp = geom.MultiPoint([1,2], [3,4])
    self.assertEqual('MULTIPOINT ((1 2), (3 4))', str(mp))

  def testMultiPointFromJTS(self):
    mp = geom.MultiPoint(self.gf.createMultiPoint([self.gf.createPoint(Coordinate(1,2)), self.gf.createPoint(Coordinate(3,4))]))
    self.assertEqual('MULTIPOINT ((1 2), (3 4))', str(mp))

  def testMultiLineString(self):
    ml = geom.MultiLineString([[1,2],[3,4]], [[5,6],[7,8]])
    self.assertEqual('MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))', str(ml))

  def testMultiLineStringFromJTS(self):
    mls = self.gf.createMultiLineString([self.gf.createLineString([Coordinate(1,2),Coordinate(3,4)]), self.gf.createLineString([Coordinate(5,6),Coordinate(7,8)])])
    ml = geom.MultiLineString(mls)
    self.assertEqual('MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))', str(ml))

  def testMultiPolygon(self):
    mp = geom.MultiPolygon([ [[1,2],[3,4],[5,6],[1,2]] ])
    self.assertEqual('MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)))', str(mp))

  def testCircularString(self):
    cs = geom.CircularString([6.12, 10.0],[7.07, 7.07],[10.0, 0.0])
    self.assertEqual('CIRCULARSTRING(6.12 10.0, 7.07 7.07, 10.0 0.0)', str(cs))
  
  def testCircularRing(self):
    cr = geom.CircularRing( [2.0, 1.0], [1.0, 2.0], [0.0, 1.0], [1.0, 0.0], [2.0, 1.0])
    self.assertEqual('CIRCULARSTRING(2.0 1.0, 1.0 2.0, 0.0 1.0, 1.0 0.0, 2.0 1.0)', str(cr))

  def testCompoundCurve(self):
    cc = geom.CompoundCurve(
        geom.CircularString([10.0, 10.0], [0.0, 20.0], [-10.0, 10.0]),
        geom.LineString([-10.0, 10.0], [-10.0, 0.0], [10.0, 0.0], [5.0, 5.0])
    )
    self.assertEqual('COMPOUNDCURVE(CIRCULARSTRING(10.0 10.0, 0.0 20.0, -10.0 10.0), (-10.0 10.0, -10.0 0.0, 10.0 0.0, 5.0 5.0))', str(cc))

  def testCompoundRing(self):
    cc = geom.CompoundRing(
        geom.CircularString([10.0, 10.0], [0.0, 20.0], [-10.0, 10.0]),
        geom.LineString([-10.0, 10.0], [-10.0, 0.0], [10.0, 0.0], [10.0, 10.0])
    )
    self.assertEqual('COMPOUNDCURVE(CIRCULARSTRING(10.0 10.0, 0.0 20.0, -10.0 10.0), (-10.0 10.0, -10.0 0.0, 10.0 0.0, 10.0 10.0))', str(cc))

  def testBounds(self):
    b = geom.Bounds(1.0, 2.0, 3.0, 4.0)
    self.assertEqual('(1.0, 2.0, 3.0, 4.0)', str(b))
 
    b = geom.Bounds(1.0, 2.0, 3.0, 4.0, 'epsg:4326')
    self.assertEqual('(1.0, 2.0, 3.0, 4.0, EPSG:4326)', str(b))
    
  def testBoundsReproject(self):
    b = geom.Bounds(-111, 44.7, -110, 44.9, 'epsg:4326')
    b1 = b.reproject('epsg:26912')
    assertClose(self, 499999, int(b1.west))
    assertClose(self, 4949624, int(b1.south))
    assertClose(self, 579224, int(b1.east))
    assertClose(self, 4972327, int(b1.north))
    
  def testBoundsScale(self):
    b = geom.Bounds(5,5,10,10)

    b1 = b.scale(2)
    assert 2.5 == b1.west
    assert 2.5 == b1.south
    assert 12.5 == b1.east
    assert 12.5 == b1.north
  
    b1 = b.scale(0.5)
    assert 6.25 == b1.west
    assert 6.25 == b1.south
    assert 8.75 == b1.east
    assert 8.75 == b1.north

  def testBoundsExpand(self):
    b1 = geom.Bounds(0,0,5,5)
    b2 = geom.Bounds(5,5,10,10)
    b1.expand(b2)

    assert 0 == b1.west and 0 == b1.south
    assert 10 == b1.east and 10 == b1.north
  
  def testBoundsAspect(self):
    assert 1.0 == float(geom.Bounds(0,0,5,5).aspect)
    assert 0.5 == float(geom.Bounds(0,0,5,10).aspect)
   
  def testMultiPolygonFromJTS(self):
    mp = geom.MultiPolygon(self.gf.createMultiPolygon([self.gf.createPolygon(self.gf.createLinearRing([Coordinate(1,2),Coordinate(3,4),Coordinate(5,6),Coordinate(1,2)]),[])]))
    self.assertEqual('MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)))', str(mp))

  def testReadWKT(self):
    g = geom.readWKT('POINT(1 2)') 
    self.assertEqual('Point',g.geometryType)
    self.assertEqual(1,g.x)
    self.assertEqual(2,g.y)

  def testReadCurvedWKT(self):
    g = geom.readWKT('CIRCULARSTRING(6.12 10.0, 7.07 7.07, 10.0 0.0)')
    self.assertEqual('CircularString', g.geometryType)

  def testReadWKB(self):
    p = geom.Point(1,2)
    wkb = geom.writeWKB(p)

    assert str(p) == str(geom.readWKB(wkb))
    assert str(p) == str(geom.readWKB(bytes.encode(wkb, 2),2))
    assert str(p) == str(geom.readWKB(bytes.encode(wkb, 8),8))
    assert str(p) == str(geom.readWKB(bytes.encode(wkb, 16),16))

  def testReadGML(self):
    """
    <gml:Point xmlns:gml="http://www.opengis.net/gml">
      <gml:coord>
        <gml:X>1.0</gml:X>
        <gml:Y>2.0</gml:Y>
      </gml:coord>
    </gml:Point>
    """
    gml = '<gml:Point xmlns:gml="http://www.opengis.net/gml"><gml:coord><gml:X>1.0</gml:X><gml:Y>2.0</gml:Y></gml:coord></gml:Point>'
    g = geom.readGML(gml)
    assert 1.0 == g.x and 2.0 == g.y

    gml = '<gml:LineString xmlns:gml="http://www.opengis.net/gml"><gml:posList>1.0 2.0 3.0 4.0</gml:posList></gml:LineString>'
    g = geom.readGML(gml, ver=3)
    assert 'LINESTRING (1 2, 3 4)' == str(g)

    gml = '<gml:Polygon xmlns:gml="http://www.opengis.net/gml/3.2"><gml:exterior><gml:LinearRing><gml:posList>1.0 2.0 3.0 4.0 5.0 6.0 1.0 2.0</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon>'
    g = geom.readGML(gml, ver=3.2)
    assert 'POLYGON ((1 2, 3 4, 5 6, 1 2))' == str(g)

  def testWriteGML(self):
    gml = geom.writeGML(geom.Point(1,2))
    p = geom.readGML(gml)
    assert 1.0 == p.x and 2.0 == p.y

    line = geom.LineString([1,2],[3,4])
    assert str(line) == str(geom.readGML(geom.writeGML(line, ver=3), ver=3)) 
   
    poly = geom.Polygon([[1,2],[3,4],[5,6],[1,2]])
    assert str(poly) == str(geom.readGML(geom.writeGML(poly,ver=3.2),ver=3.2)) 

  def testInterpolatePoint(self):
    line = geom.LineString(
        (1137466.548141059, 650434.9943107369),
        (1175272.4129268457, 648011.541439853),
        (1185935.6055587344, 632986.1336403737)
    )

    # start
    point1 = line.interpolatePoint(0)
    assert str(line.startPoint) == str(point1)

    # middle
    point2 = line.interpolatePoint(0.5)
    assert "POINT (1165562.9204493894 648633.9448037925)" == str(point2)

    # end
    point3 = line.interpolatePoint(1.0)
    assert str(line.endPoint) == str(point3)

  def testLocatePoint(self):
    line = geom.LineString(
        (1137466.548141059, 650434.9943107369),
        (1175272.4129268457, 648011.541439853),
        (1185935.6055587344, 632986.1336403737)
    )
    point = geom.Point(1153461.34, 649950.30)
    position = line.locatePoint(point)
    self.assertAlmostEqual(0.284, position, places=3)
    position = line.locatePoint(1153461.34, 649950.30)
    self.assertAlmostEqual(0.284, position, places=3)

  def testPlacePoint(self):
    line = geom.LineString(
        (1137466.548141059, 650434.9943107369),
        (1175272.4129268457, 648011.541439853),
        (1185935.6055587344, 632986.1336403737)
    )
    point1 = geom.Point(1153461.34, 649950.30)
    point2 = line.placePoint(point1)
    assert "POINT (1153426.8271476042 649411.899502625)" == str(point2)
    point3 = line.placePoint(1153461.34, 649950.30)
    assert "POINT (1153426.8271476042 649411.899502625)" == str(point3)

  def testSubLine(self):
    line = geom.LineString(
        (1137466.548141059, 650434.9943107369),
        (1175272.4129268457, 648011.541439853),
        (1185935.6055587344, 632986.1336403737)
    )
    subLine = line.subLine(0.33, 0.67)
    assert "LINESTRING (1156010.153864557 649246.3016361536, 1175115.6870342216 648021.5879714314)" == str(subLine)
示例#10
0
 def setUp(self):
     self.gf = GeometryFactory()
示例#11
0
class GeomTest(unittest.TestCase):
    def setUp(self):
        self.gf = GeometryFactory()

    def testPoint(self):
        p = geom.Point(1, 2)
        self.assertEqual('POINT (1 2)', str(p))

    def testPointFromJTS(self):
        p = geom.Point(self.gf.createPoint(Coordinate(1, 2)))
        self.assertEqual('POINT (1 2)', str(p))

    def testLineString(self):
        l = geom.LineString((1, 2), (3, 4))
        self.assertEqual('LINESTRING (1 2, 3 4)', str(l))

    def testLineStringFromJTS(self):
        ls = self.gf.createLineString([Coordinate(1, 2), Coordinate(3, 4)])
        l = geom.LineString(ls)
        self.assertEqual('LINESTRING (1 2, 3 4)', str(l))

    def testPolygon(self):
        p = geom.Polygon([[1, 2], [3, 4], [5, 6], [1, 2]])
        self.assertEqual('POLYGON ((1 2, 3 4, 5 6, 1 2))', str(p))

    def testPolygonFromJTS(self):
        poly = self.gf.createPolygon(
            self.gf.createLinearRing([
                Coordinate(1, 2),
                Coordinate(3, 4),
                Coordinate(5, 6),
                Coordinate(1, 2)
            ]), [])
        p = geom.Polygon(poly)
        self.assertEqual('POLYGON ((1 2, 3 4, 5 6, 1 2))', str(p))

    def testMultiPoint(self):
        mp = geom.MultiPoint([1, 2], [3, 4])
        self.assertEqual('MULTIPOINT ((1 2), (3 4))', str(mp))

    def testMultiPointFromJTS(self):
        mp = geom.MultiPoint(
            self.gf.createMultiPoint([
                self.gf.createPoint(Coordinate(1, 2)),
                self.gf.createPoint(Coordinate(3, 4))
            ]))
        self.assertEqual('MULTIPOINT ((1 2), (3 4))', str(mp))

    def testMultiLineString(self):
        ml = geom.MultiLineString([[1, 2], [3, 4]], [[5, 6], [7, 8]])
        self.assertEqual('MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))', str(ml))

    def testMultiLineStringFromJTS(self):
        mls = self.gf.createMultiLineString([
            self.gf.createLineString([Coordinate(1, 2),
                                      Coordinate(3, 4)]),
            self.gf.createLineString([Coordinate(5, 6),
                                      Coordinate(7, 8)])
        ])
        ml = geom.MultiLineString(mls)
        self.assertEqual('MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))', str(ml))

    def testMultiPolygon(self):
        mp = geom.MultiPolygon([[[1, 2], [3, 4], [5, 6], [1, 2]]])
        self.assertEqual('MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)))', str(mp))

    def testBounds(self):
        b = geom.Bounds(1.0, 2.0, 3.0, 4.0)
        self.assertEqual('(1.0, 2.0, 3.0, 4.0)', str(b))

        b = geom.Bounds(1.0, 2.0, 3.0, 4.0, 'epsg:4326')
        self.assertEqual('(1.0, 2.0, 3.0, 4.0, EPSG:4326)', str(b))

    def testBoundsReproject(self):
        b = geom.Bounds(-111, 44.7, -110, 44.9, 'epsg:4326')
        b1 = b.reproject('epsg:26912')
        self.assertEqual(499999, int(b1.west))
        self.assertEqual(4949624, int(b1.south))
        self.assertEqual(579224, int(b1.east))
        self.assertEqual(4972327, int(b1.north))

    def testBoundsScale(self):
        b = geom.Bounds(5, 5, 10, 10)

        b1 = b.scale(2)
        assert 2.5 == b1.west
        assert 2.5 == b1.south
        assert 12.5 == b1.east
        assert 12.5 == b1.north

        b1 = b.scale(0.5)
        assert 6.25 == b1.west
        assert 6.25 == b1.south
        assert 8.75 == b1.east
        assert 8.75 == b1.north

    def testBoundsExpand(self):
        b1 = geom.Bounds(0, 0, 5, 5)
        b2 = geom.Bounds(5, 5, 10, 10)
        b1.expand(b2)

        assert 0 == b1.west and 0 == b1.south
        assert 10 == b1.east and 10 == b1.north

    def testMultiPolygonFromJTS(self):
        mp = geom.MultiPolygon(
            self.gf.createMultiPolygon([
                self.gf.createPolygon(
                    self.gf.createLinearRing([
                        Coordinate(1, 2),
                        Coordinate(3, 4),
                        Coordinate(5, 6),
                        Coordinate(1, 2)
                    ]), [])
            ]))
        self.assertEqual('MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)))', str(mp))

    def testFromWKT(self):
        g = geom.fromWKT('POINT(1 2)')
        self.assertEqual('Point', g.geometryType)
        self.assertEqual(1, g.x)
        self.assertEqual(2, g.y)
示例#12
0
class GeomTest(unittest.TestCase):
    def setUp(self):
        self.gf = GeometryFactory()

    def testPoint(self):
        p = geom.Point(1, 2)
        self.assertEqual('POINT (1 2)', str(p))

    def testPointFromJTS(self):
        p = geom.Point(self.gf.createPoint(Coordinate(1, 2)))
        self.assertEqual('POINT (1 2)', str(p))

    def testLineString(self):
        l = geom.LineString((1, 2), (3, 4))
        self.assertEqual('LINESTRING (1 2, 3 4)', str(l))

    def testLineStringFromJTS(self):
        ls = self.gf.createLineString([Coordinate(1, 2), Coordinate(3, 4)])
        l = geom.LineString(ls)
        self.assertEqual('LINESTRING (1 2, 3 4)', str(l))

    def testPolygon(self):
        p = geom.Polygon([[1, 2], [3, 4], [5, 6], [1, 2]])
        self.assertEqual('POLYGON ((1 2, 3 4, 5 6, 1 2))', str(p))

    def testPolygonFromJTS(self):
        poly = self.gf.createPolygon(
            self.gf.createLinearRing([
                Coordinate(1, 2),
                Coordinate(3, 4),
                Coordinate(5, 6),
                Coordinate(1, 2)
            ]), [])
        p = geom.Polygon(poly)
        self.assertEqual('POLYGON ((1 2, 3 4, 5 6, 1 2))', str(p))

    def testMultiPoint(self):
        mp = geom.MultiPoint([1, 2], [3, 4])
        self.assertEqual('MULTIPOINT ((1 2), (3 4))', str(mp))

    def testMultiPointFromJTS(self):
        mp = geom.MultiPoint(
            self.gf.createMultiPoint([
                self.gf.createPoint(Coordinate(1, 2)),
                self.gf.createPoint(Coordinate(3, 4))
            ]))
        self.assertEqual('MULTIPOINT ((1 2), (3 4))', str(mp))

    def testMultiLineString(self):
        ml = geom.MultiLineString([[1, 2], [3, 4]], [[5, 6], [7, 8]])
        self.assertEqual('MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))', str(ml))

    def testMultiLineStringFromJTS(self):
        mls = self.gf.createMultiLineString([
            self.gf.createLineString([Coordinate(1, 2),
                                      Coordinate(3, 4)]),
            self.gf.createLineString([Coordinate(5, 6),
                                      Coordinate(7, 8)])
        ])
        ml = geom.MultiLineString(mls)
        self.assertEqual('MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))', str(ml))

    def testMultiPolygon(self):
        mp = geom.MultiPolygon([[[1, 2], [3, 4], [5, 6], [1, 2]]])
        self.assertEqual('MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)))', str(mp))

    def testBounds(self):
        b = geom.Bounds(1.0, 2.0, 3.0, 4.0)
        self.assertEqual('(1.0, 2.0, 3.0, 4.0)', str(b))

        b = geom.Bounds(1.0, 2.0, 3.0, 4.0, 'epsg:4326')
        self.assertEqual('(1.0, 2.0, 3.0, 4.0, EPSG:4326)', str(b))

    def testBoundsReproject(self):
        b = geom.Bounds(-111, 44.7, -110, 44.9, 'epsg:4326')
        b1 = b.reproject('epsg:26912')
        assertClose(self, 499999, int(b1.west))
        assertClose(self, 4949624, int(b1.south))
        assertClose(self, 579224, int(b1.east))
        assertClose(self, 4972327, int(b1.north))

    def testBoundsScale(self):
        b = geom.Bounds(5, 5, 10, 10)

        b1 = b.scale(2)
        assert 2.5 == b1.west
        assert 2.5 == b1.south
        assert 12.5 == b1.east
        assert 12.5 == b1.north

        b1 = b.scale(0.5)
        assert 6.25 == b1.west
        assert 6.25 == b1.south
        assert 8.75 == b1.east
        assert 8.75 == b1.north

    def testBoundsExpand(self):
        b1 = geom.Bounds(0, 0, 5, 5)
        b2 = geom.Bounds(5, 5, 10, 10)
        b1.expand(b2)

        assert 0 == b1.west and 0 == b1.south
        assert 10 == b1.east and 10 == b1.north

    def testBoundsAspect(self):
        assert 1.0 == float(geom.Bounds(0, 0, 5, 5).aspect)
        assert 0.5 == float(geom.Bounds(0, 0, 5, 10).aspect)

    def testMultiPolygonFromJTS(self):
        mp = geom.MultiPolygon(
            self.gf.createMultiPolygon([
                self.gf.createPolygon(
                    self.gf.createLinearRing([
                        Coordinate(1, 2),
                        Coordinate(3, 4),
                        Coordinate(5, 6),
                        Coordinate(1, 2)
                    ]), [])
            ]))
        self.assertEqual('MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)))', str(mp))

    def testReadWKT(self):
        g = geom.readWKT('POINT(1 2)')
        self.assertEqual('Point', g.geometryType)
        self.assertEqual(1, g.x)
        self.assertEqual(2, g.y)

    def testReadWKB(self):
        p = geom.Point(1, 2)
        wkb = geom.writeWKB(p)

        assert str(p) == str(geom.readWKB(wkb))
        assert str(p) == str(geom.readWKB(bytes.encode(wkb, 2), 2))
        assert str(p) == str(geom.readWKB(bytes.encode(wkb, 8), 8))
        assert str(p) == str(geom.readWKB(bytes.encode(wkb, 16), 16))

    def testReadGML(self):
        """
    <gml:Point xmlns:gml="http://www.opengis.net/gml">
      <gml:coord>
        <gml:X>1.0</gml:X>
        <gml:Y>2.0</gml:Y>
      </gml:coord>
    </gml:Point>
    """
        gml = '<gml:Point xmlns:gml="http://www.opengis.net/gml"><gml:coord><gml:X>1.0</gml:X><gml:Y>2.0</gml:Y></gml:coord></gml:Point>'
        g = geom.readGML(gml)
        assert 1.0 == g.x and 2.0 == g.y

        gml = '<gml:LineString xmlns:gml="http://www.opengis.net/gml"><gml:posList>1.0 2.0 3.0 4.0</gml:posList></gml:LineString>'
        g = geom.readGML(gml, ver=3)
        assert 'LINESTRING (1 2, 3 4)' == str(g)

        gml = '<gml:Polygon xmlns:gml="http://www.opengis.net/gml/3.2"><gml:exterior><gml:LinearRing><gml:posList>1.0 2.0 3.0 4.0 5.0 6.0 1.0 2.0</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon>'
        g = geom.readGML(gml, ver=3.2)
        assert 'POLYGON ((1 2, 3 4, 5 6, 1 2))' == str(g)

    def testWriteGML(self):
        gml = geom.writeGML(geom.Point(1, 2))
        p = geom.readGML(gml)
        assert 1.0 == p.x and 2.0 == p.y

        line = geom.LineString([1, 2], [3, 4])
        assert str(line) == str(geom.readGML(geom.writeGML(line, ver=3),
                                             ver=3))

        poly = geom.Polygon([[1, 2], [3, 4], [5, 6], [1, 2]])
        assert str(poly) == str(
            geom.readGML(geom.writeGML(poly, ver=3.2), ver=3.2))
示例#13
0
class GeomTest(unittest.TestCase):

  def setUp(self):
    self.gf = GeometryFactory()

  def testPoint(self):
    p = geom.Point(1,2)
    self.assertEqual('POINT (1 2)', str(p))

  def testPointFromJTS(self):
    p = geom.Point(self.gf.createPoint(Coordinate(1,2)))
    self.assertEqual('POINT (1 2)', str(p))

  def testLineString(self):
    l = geom.LineString((1,2),(3,4))
    self.assertEqual('LINESTRING (1 2, 3 4)', str(l)) 

  def testLineStringFromJTS(self):
    ls = self.gf.createLineString([Coordinate(1,2), Coordinate(3,4)])
    l = geom.LineString(ls)
    self.assertEqual('LINESTRING (1 2, 3 4)', str(l)) 
  
  def testPolygon(self):
    p = geom.Polygon([[1,2],[3,4],[5,6],[1,2]])
    self.assertEqual('POLYGON ((1 2, 3 4, 5 6, 1 2))', str(p)) 

  def testPolygonFromJTS(self):
    poly = self.gf.createPolygon(self.gf.createLinearRing([Coordinate(1,2),Coordinate(3,4), Coordinate(5,6), Coordinate(1,2)]), [])
    p = geom.Polygon(poly)
    self.assertEqual('POLYGON ((1 2, 3 4, 5 6, 1 2))', str(p)) 

  def testMultiPoint(self):
    mp = geom.MultiPoint([1,2], [3,4])
    self.assertEqual('MULTIPOINT ((1 2), (3 4))', str(mp))

  def testMultiPointFromJTS(self):
    mp = geom.MultiPoint(self.gf.createMultiPoint([self.gf.createPoint(Coordinate(1,2)), self.gf.createPoint(Coordinate(3,4))]))
    self.assertEqual('MULTIPOINT ((1 2), (3 4))', str(mp))

  def testMultiLineString(self):
    ml = geom.MultiLineString([[1,2],[3,4]], [[5,6],[7,8]])
    self.assertEqual('MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))', str(ml))

  def testMultiLineStringFromJTS(self):
    mls = self.gf.createMultiLineString([self.gf.createLineString([Coordinate(1,2),Coordinate(3,4)]), self.gf.createLineString([Coordinate(5,6),Coordinate(7,8)])])
    ml = geom.MultiLineString(mls)
    self.assertEqual('MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))', str(ml))

  def testMultiPolygon(self):
    mp = geom.MultiPolygon([ [[1,2],[3,4],[5,6],[1,2]] ])
    self.assertEqual('MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)))', str(mp))

  def testBounds(self):
    b = geom.Bounds(1.0, 2.0, 3.0, 4.0)
    self.assertEqual('(1.0, 2.0, 3.0, 4.0)', str(b))
 
    b = geom.Bounds(1.0, 2.0, 3.0, 4.0, 'epsg:4326')
    self.assertEqual('(1.0, 2.0, 3.0, 4.0, EPSG:4326)', str(b))
    
  def testBoundsReproject(self):
    b = geom.Bounds(-111, 44.7, -110, 44.9, 'epsg:4326')
    b1 = b.reproject('epsg:26912')
    self.assertEqual(499999, int(b1.west))
    self.assertEqual(4949624, int(b1.south))
    self.assertEqual(579224, int(b1.east))
    self.assertEqual(4972327, int(b1.north))
    
  def testBoundsScale(self):
    b = geom.Bounds(5,5,10,10)

    b1 = b.scale(2)
    assert 2.5 == b1.west
    assert 2.5 == b1.south
    assert 12.5 == b1.east
    assert 12.5 == b1.north
  
    b1 = b.scale(0.5)
    assert 6.25 == b1.west
    assert 6.25 == b1.south
    assert 8.75 == b1.east
    assert 8.75 == b1.north

  def testBoundsExpand(self):
    b1 = geom.Bounds(0,0,5,5)
    b2 = geom.Bounds(5,5,10,10)
    b1.expand(b2)

    assert 0 == b1.west and 0 == b1.south
    assert 10 == b1.east and 10 == b1.north
  
  def testMultiPolygonFromJTS(self):
    mp = geom.MultiPolygon(self.gf.createMultiPolygon([self.gf.createPolygon(self.gf.createLinearRing([Coordinate(1,2),Coordinate(3,4),Coordinate(5,6),Coordinate(1,2)]),[])]))
    self.assertEqual('MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)))', str(mp))

  def testFromWKT(self):
    g = geom.fromWKT('POINT(1 2)') 
    self.assertEqual('Point',g.geometryType)
    self.assertEqual(1,g.x)
    self.assertEqual(2,g.y)
示例#14
0
 def getVertexGeom(self):
     return WKBWriter().bytesToHex(WKBWriter().write(
         GeometryFactory(PrecisionModel(), 4326).createPoint(
             self.srcstate.getVertex().getCoordinate())))
示例#15
0
class GeomTest(unittest.TestCase):

  def setUp(self):
    self.gf = GeometryFactory()

  def testPoint(self):
    p = geom.Point(1,2)
    self.assertEqual('POINT (1 2)', str(p))

  def testPointFromJTS(self):
    p = geom.Point(self.gf.createPoint(Coordinate(1,2)))
    self.assertEqual('POINT (1 2)', str(p))

  def testLineString(self):
    l = geom.LineString((1,2),(3,4))
    self.assertEqual('LINESTRING (1 2, 3 4)', str(l)) 

  def testLineStringFromJTS(self):
    ls = self.gf.createLineString([Coordinate(1,2), Coordinate(3,4)])
    l = geom.LineString(ls)
    self.assertEqual('LINESTRING (1 2, 3 4)', str(l)) 
  
  def testPolygon(self):
    p = geom.Polygon([[1,2],[3,4],[5,6],[1,2]])
    self.assertEqual('POLYGON ((1 2, 3 4, 5 6, 1 2))', str(p)) 

  def testPolygonFromJTS(self):
    poly = self.gf.createPolygon(self.gf.createLinearRing([Coordinate(1,2),Coordinate(3,4), Coordinate(5,6), Coordinate(1,2)]), [])
    p = geom.Polygon(poly)
    self.assertEqual('POLYGON ((1 2, 3 4, 5 6, 1 2))', str(p)) 

  def testMultiPoint(self):
    mp = geom.MultiPoint([1,2], [3,4])
    self.assertEqual('MULTIPOINT ((1 2), (3 4))', str(mp))

  def testMultiPointFromJTS(self):
    mp = geom.MultiPoint(self.gf.createMultiPoint([self.gf.createPoint(Coordinate(1,2)), self.gf.createPoint(Coordinate(3,4))]))
    self.assertEqual('MULTIPOINT ((1 2), (3 4))', str(mp))

  def testMultiLineString(self):
    ml = geom.MultiLineString([[1,2],[3,4]], [[5,6],[7,8]])
    self.assertEqual('MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))', str(ml))

  def testMultiLineStringFromJTS(self):
    mls = self.gf.createMultiLineString([self.gf.createLineString([Coordinate(1,2),Coordinate(3,4)]), self.gf.createLineString([Coordinate(5,6),Coordinate(7,8)])])
    ml = geom.MultiLineString(mls)
    self.assertEqual('MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))', str(ml))

  def testMultiPolygon(self):
    mp = geom.MultiPolygon([ [[1,2],[3,4],[5,6],[1,2]] ])
    self.assertEqual('MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)))', str(mp))

  def testCircularString(self):
    cs = geom.CircularString([6.12, 10.0],[7.07, 7.07],[10.0, 0.0])
    self.assertEqual('CIRCULARSTRING(6.12 10.0, 7.07 7.07, 10.0 0.0)', str(cs))
  
  def testCircularRing(self):
    cr = geom.CircularRing( [2.0, 1.0], [1.0, 2.0], [0.0, 1.0], [1.0, 0.0], [2.0, 1.0])
    self.assertEqual('CIRCULARSTRING(2.0 1.0, 1.0 2.0, 0.0 1.0, 1.0 0.0, 2.0 1.0)', str(cr))

  def testCompoundCurve(self):
    cc = geom.CompoundCurve(
        geom.CircularString([10.0, 10.0], [0.0, 20.0], [-10.0, 10.0]),
        geom.LineString([-10.0, 10.0], [-10.0, 0.0], [10.0, 0.0], [5.0, 5.0])
    )
    self.assertEqual('COMPOUNDCURVE(CIRCULARSTRING(10.0 10.0, 0.0 20.0, -10.0 10.0), (-10.0 10.0, -10.0 0.0, 10.0 0.0, 5.0 5.0))', str(cc))

  def testCompoundRing(self):
    cc = geom.CompoundRing(
        geom.CircularString([10.0, 10.0], [0.0, 20.0], [-10.0, 10.0]),
        geom.LineString([-10.0, 10.0], [-10.0, 0.0], [10.0, 0.0], [10.0, 10.0])
    )
    self.assertEqual('COMPOUNDCURVE(CIRCULARSTRING(10.0 10.0, 0.0 20.0, -10.0 10.0), (-10.0 10.0, -10.0 0.0, 10.0 0.0, 10.0 10.0))', str(cc))

  def testBounds(self):
    b = geom.Bounds(1.0, 2.0, 3.0, 4.0)
    self.assertEqual('(1.0, 2.0, 3.0, 4.0)', str(b))
 
    b = geom.Bounds(1.0, 2.0, 3.0, 4.0, 'epsg:4326')
    self.assertEqual('(1.0, 2.0, 3.0, 4.0, EPSG:4326)', str(b))
    
  def testBoundsReproject(self):
    b = geom.Bounds(-111, 44.7, -110, 44.9, 'epsg:4326')
    b1 = b.reproject('epsg:26912')
    assertClose(self, 499999, int(b1.west))
    assertClose(self, 4949624, int(b1.south))
    assertClose(self, 579224, int(b1.east))
    assertClose(self, 4972327, int(b1.north))
    
  def testBoundsScale(self):
    b = geom.Bounds(5,5,10,10)

    b1 = b.scale(2)
    assert 2.5 == b1.west
    assert 2.5 == b1.south
    assert 12.5 == b1.east
    assert 12.5 == b1.north
  
    b1 = b.scale(0.5)
    assert 6.25 == b1.west
    assert 6.25 == b1.south
    assert 8.75 == b1.east
    assert 8.75 == b1.north

  def testBoundsExpand(self):
    b1 = geom.Bounds(0,0,5,5)
    b2 = geom.Bounds(5,5,10,10)
    b1.expand(b2)

    assert 0 == b1.west and 0 == b1.south
    assert 10 == b1.east and 10 == b1.north
  
  def testBoundsAspect(self):
    assert 1.0 == float(geom.Bounds(0,0,5,5).aspect)
    assert 0.5 == float(geom.Bounds(0,0,5,10).aspect)
   
  def testMultiPolygonFromJTS(self):
    mp = geom.MultiPolygon(self.gf.createMultiPolygon([self.gf.createPolygon(self.gf.createLinearRing([Coordinate(1,2),Coordinate(3,4),Coordinate(5,6),Coordinate(1,2)]),[])]))
    self.assertEqual('MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)))', str(mp))

  def testReadWKT(self):
    g = geom.readWKT('POINT(1 2)') 
    self.assertEqual('Point',g.geometryType)
    self.assertEqual(1,g.x)
    self.assertEqual(2,g.y)

  def testReadCurvedWKT(self):
    g = geom.readWKT('CIRCULARSTRING(6.12 10.0, 7.07 7.07, 10.0 0.0)')
    self.assertEqual('CircularString', g.geometryType)

  def testReadWKB(self):
    p = geom.Point(1,2)
    wkb = geom.writeWKB(p)

    assert str(p) == str(geom.readWKB(wkb))
    assert str(p) == str(geom.readWKB(bytes.encode(wkb, 2),2))
    assert str(p) == str(geom.readWKB(bytes.encode(wkb, 8),8))
    assert str(p) == str(geom.readWKB(bytes.encode(wkb, 16),16))

  def testReadGML(self):
    """
    <gml:Point xmlns:gml="http://www.opengis.net/gml">
      <gml:coord>
        <gml:X>1.0</gml:X>
        <gml:Y>2.0</gml:Y>
      </gml:coord>
    </gml:Point>
    """
    gml = '<gml:Point xmlns:gml="http://www.opengis.net/gml"><gml:coord><gml:X>1.0</gml:X><gml:Y>2.0</gml:Y></gml:coord></gml:Point>'
    g = geom.readGML(gml)
    assert 1.0 == g.x and 2.0 == g.y

    gml = '<gml:LineString xmlns:gml="http://www.opengis.net/gml"><gml:posList>1.0 2.0 3.0 4.0</gml:posList></gml:LineString>'
    g = geom.readGML(gml, ver=3)
    assert 'LINESTRING (1 2, 3 4)' == str(g)

    gml = '<gml:Polygon xmlns:gml="http://www.opengis.net/gml/3.2"><gml:exterior><gml:LinearRing><gml:posList>1.0 2.0 3.0 4.0 5.0 6.0 1.0 2.0</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon>'
    g = geom.readGML(gml, ver=3.2)
    assert 'POLYGON ((1 2, 3 4, 5 6, 1 2))' == str(g)

  def testWriteGML(self):
    gml = geom.writeGML(geom.Point(1,2))
    p = geom.readGML(gml)
    assert 1.0 == p.x and 2.0 == p.y

    line = geom.LineString([1,2],[3,4])
    assert str(line) == str(geom.readGML(geom.writeGML(line, ver=3), ver=3)) 
   
    poly = geom.Polygon([[1,2],[3,4],[5,6],[1,2]])
    assert str(poly) == str(geom.readGML(geom.writeGML(poly,ver=3.2),ver=3.2)) 
示例#16
0
"""
The :mod:`geom` module provides geometry classes and utilities for the construction and manipulation of geometry objects.
"""

from com.vividsolutions.jts.geom import GeometryFactory
from com.vividsolutions.jts.geom import Geometry as _Geometry
from com.vividsolutions.jts.geom.prep import PreparedGeometryFactory
from com.vividsolutions.jts.simplify import DouglasPeuckerSimplifier as DP

_factory = GeometryFactory()
_prepfactory = PreparedGeometryFactory()

Geometry = _Geometry
"""
Base class for all geometry classes.
"""


def prepare(g):
    """
  Constructs a prepared geometry. Prepared geometries make repeated spatial 
  operations (such as intersection) more efficient.

  *g* is the :class:`Geometry <geoscript.geom.Geometry>` to prepare.

  >>> from geoscript.geom import readWKT
  >>> prep = prepare(readWKT('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))'))
  >>> prep.intersects(readWKT('POLYGON ((4 4, 6 4, 6 6, 4 6, 4 4))'))
  True
  """
    return _prepfactory.create(g)
示例#17
0
class GeomTest(unittest.TestCase):
    def setUp(self):
        self.gf = GeometryFactory()

    def testPoint(self):
        p = geom.Point(1, 2)
        self.assertEqual('POINT (1 2)', str(p))

    def testPointFromJTS(self):
        p = geom.Point(self.gf.createPoint(Coordinate(1, 2)))
        self.assertEqual('POINT (1 2)', str(p))

    def testLineString(self):
        l = geom.LineString((1, 2), (3, 4))
        self.assertEqual('LINESTRING (1 2, 3 4)', str(l))

    def testLineStringFromJTS(self):
        ls = self.gf.createLineString([Coordinate(1, 2), Coordinate(3, 4)])
        l = geom.LineString(ls)
        self.assertEqual('LINESTRING (1 2, 3 4)', str(l))

    def testPolygon(self):
        p = geom.Polygon([[1, 2], [3, 4], [5, 6], [1, 2]])
        self.assertEqual('POLYGON ((1 2, 3 4, 5 6, 1 2))', str(p))

    def testPolygonFromJTS(self):
        poly = self.gf.createPolygon(
            self.gf.createLinearRing([
                Coordinate(1, 2),
                Coordinate(3, 4),
                Coordinate(5, 6),
                Coordinate(1, 2)
            ]), [])
        p = geom.Polygon(poly)
        self.assertEqual('POLYGON ((1 2, 3 4, 5 6, 1 2))', str(p))

    def testMultiPoint(self):
        mp = geom.MultiPoint([1, 2], [3, 4])
        self.assertEqual('MULTIPOINT ((1 2), (3 4))', str(mp))

    def testMultiPointFromJTS(self):
        mp = geom.MultiPoint(
            self.gf.createMultiPoint([
                self.gf.createPoint(Coordinate(1, 2)),
                self.gf.createPoint(Coordinate(3, 4))
            ]))
        self.assertEqual('MULTIPOINT ((1 2), (3 4))', str(mp))

    def testMultiLineString(self):
        ml = geom.MultiLineString([[1, 2], [3, 4]], [[5, 6], [7, 8]])
        self.assertEqual('MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))', str(ml))

    def testMultiLineStringFromJTS(self):
        mls = self.gf.createMultiLineString([
            self.gf.createLineString([Coordinate(1, 2),
                                      Coordinate(3, 4)]),
            self.gf.createLineString([Coordinate(5, 6),
                                      Coordinate(7, 8)])
        ])
        ml = geom.MultiLineString(mls)
        self.assertEqual('MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))', str(ml))

    def testMultiPolygon(self):
        mp = geom.MultiPolygon([[[1, 2], [3, 4], [5, 6], [1, 2]]])
        self.assertEqual('MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)))', str(mp))

    def testCircularString(self):
        cs = geom.CircularString([6.12, 10.0], [7.07, 7.07], [10.0, 0.0])
        self.assertEqual('CIRCULARSTRING(6.12 10.0, 7.07 7.07, 10.0 0.0)',
                         str(cs))

    def testCircularRing(self):
        cr = geom.CircularRing([2.0, 1.0], [1.0, 2.0], [0.0, 1.0], [1.0, 0.0],
                               [2.0, 1.0])
        self.assertEqual(
            'CIRCULARSTRING(2.0 1.0, 1.0 2.0, 0.0 1.0, 1.0 0.0, 2.0 1.0)',
            str(cr))

    def testCompoundCurve(self):
        cc = geom.CompoundCurve(
            geom.CircularString([10.0, 10.0], [0.0, 20.0], [-10.0, 10.0]),
            geom.LineString([-10.0, 10.0], [-10.0, 0.0], [10.0, 0.0],
                            [5.0, 5.0]))
        self.assertEqual(
            'COMPOUNDCURVE(CIRCULARSTRING(10.0 10.0, 0.0 20.0, -10.0 10.0), (-10.0 10.0, -10.0 0.0, 10.0 0.0, 5.0 5.0))',
            str(cc))

    def testCompoundRing(self):
        cc = geom.CompoundRing(
            geom.CircularString([10.0, 10.0], [0.0, 20.0], [-10.0, 10.0]),
            geom.LineString([-10.0, 10.0], [-10.0, 0.0], [10.0, 0.0],
                            [10.0, 10.0]))
        self.assertEqual(
            'COMPOUNDCURVE(CIRCULARSTRING(10.0 10.0, 0.0 20.0, -10.0 10.0), (-10.0 10.0, -10.0 0.0, 10.0 0.0, 10.0 10.0))',
            str(cc))

    def testBounds(self):
        b = geom.Bounds(1.0, 2.0, 3.0, 4.0)
        self.assertEqual('(1.0, 2.0, 3.0, 4.0)', str(b))

        b = geom.Bounds(1.0, 2.0, 3.0, 4.0, 'epsg:4326')
        self.assertEqual('(1.0, 2.0, 3.0, 4.0, EPSG:4326)', str(b))

    def testBoundsReproject(self):
        b = geom.Bounds(-111, 44.7, -110, 44.9, 'epsg:4326')
        b1 = b.reproject('epsg:26912')
        assertClose(self, 499999, int(b1.west))
        assertClose(self, 4949624, int(b1.south))
        assertClose(self, 579224, int(b1.east))
        assertClose(self, 4972327, int(b1.north))

    def testBoundsScale(self):
        b = geom.Bounds(5, 5, 10, 10)

        b1 = b.scale(2)
        assert 2.5 == b1.west
        assert 2.5 == b1.south
        assert 12.5 == b1.east
        assert 12.5 == b1.north

        b1 = b.scale(0.5)
        assert 6.25 == b1.west
        assert 6.25 == b1.south
        assert 8.75 == b1.east
        assert 8.75 == b1.north

    def testBoundsExpand(self):
        b1 = geom.Bounds(0, 0, 5, 5)
        b2 = geom.Bounds(5, 5, 10, 10)
        b1.expand(b2)

        assert 0 == b1.west and 0 == b1.south
        assert 10 == b1.east and 10 == b1.north

    def testBoundsAspect(self):
        assert 1.0 == float(geom.Bounds(0, 0, 5, 5).aspect)
        assert 0.5 == float(geom.Bounds(0, 0, 5, 10).aspect)

    def testMultiPolygonFromJTS(self):
        mp = geom.MultiPolygon(
            self.gf.createMultiPolygon([
                self.gf.createPolygon(
                    self.gf.createLinearRing([
                        Coordinate(1, 2),
                        Coordinate(3, 4),
                        Coordinate(5, 6),
                        Coordinate(1, 2)
                    ]), [])
            ]))
        self.assertEqual('MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)))', str(mp))

    def testReadWKT(self):
        g = geom.readWKT('POINT(1 2)')
        self.assertEqual('Point', g.geometryType)
        self.assertEqual(1, g.x)
        self.assertEqual(2, g.y)

    def testReadCurvedWKT(self):
        g = geom.readWKT('CIRCULARSTRING(6.12 10.0, 7.07 7.07, 10.0 0.0)')
        self.assertEqual('CircularString', g.geometryType)

    def testReadWKB(self):
        p = geom.Point(1, 2)
        wkb = geom.writeWKB(p)

        assert str(p) == str(geom.readWKB(wkb))
        assert str(p) == str(geom.readWKB(bytes.encode(wkb, 2), 2))
        assert str(p) == str(geom.readWKB(bytes.encode(wkb, 8), 8))
        assert str(p) == str(geom.readWKB(bytes.encode(wkb, 16), 16))

    def testReadGML(self):
        """
    <gml:Point xmlns:gml="http://www.opengis.net/gml">
      <gml:coord>
        <gml:X>1.0</gml:X>
        <gml:Y>2.0</gml:Y>
      </gml:coord>
    </gml:Point>
    """
        gml = '<gml:Point xmlns:gml="http://www.opengis.net/gml"><gml:coord><gml:X>1.0</gml:X><gml:Y>2.0</gml:Y></gml:coord></gml:Point>'
        g = geom.readGML(gml)
        assert 1.0 == g.x and 2.0 == g.y

        gml = '<gml:LineString xmlns:gml="http://www.opengis.net/gml"><gml:posList>1.0 2.0 3.0 4.0</gml:posList></gml:LineString>'
        g = geom.readGML(gml, ver=3)
        assert 'LINESTRING (1 2, 3 4)' == str(g)

        gml = '<gml:Polygon xmlns:gml="http://www.opengis.net/gml/3.2"><gml:exterior><gml:LinearRing><gml:posList>1.0 2.0 3.0 4.0 5.0 6.0 1.0 2.0</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon>'
        g = geom.readGML(gml, ver=3.2)
        assert 'POLYGON ((1 2, 3 4, 5 6, 1 2))' == str(g)

    def testWriteGML(self):
        gml = geom.writeGML(geom.Point(1, 2))
        p = geom.readGML(gml)
        assert 1.0 == p.x and 2.0 == p.y

        line = geom.LineString([1, 2], [3, 4])
        assert str(line) == str(geom.readGML(geom.writeGML(line, ver=3),
                                             ver=3))

        poly = geom.Polygon([[1, 2], [3, 4], [5, 6], [1, 2]])
        assert str(poly) == str(
            geom.readGML(geom.writeGML(poly, ver=3.2), ver=3.2))

    def testInterpolatePoint(self):
        line = geom.LineString((1137466.548141059, 650434.9943107369),
                               (1175272.4129268457, 648011.541439853),
                               (1185935.6055587344, 632986.1336403737))

        # start
        point1 = line.interpolatePoint(0)
        assert str(line.startPoint) == str(point1)

        # middle
        point2 = line.interpolatePoint(0.5)
        assert "POINT (1165562.9204493894 648633.9448037925)" == str(point2)

        # end
        point3 = line.interpolatePoint(1.0)
        assert str(line.endPoint) == str(point3)

    def testLocatePoint(self):
        line = geom.LineString((1137466.548141059, 650434.9943107369),
                               (1175272.4129268457, 648011.541439853),
                               (1185935.6055587344, 632986.1336403737))
        point = geom.Point(1153461.34, 649950.30)
        position = line.locatePoint(point)
        self.assertAlmostEqual(0.284, position, places=3)
        position = line.locatePoint(1153461.34, 649950.30)
        self.assertAlmostEqual(0.284, position, places=3)

    def testPlacePoint(self):
        line = geom.LineString((1137466.548141059, 650434.9943107369),
                               (1175272.4129268457, 648011.541439853),
                               (1185935.6055587344, 632986.1336403737))
        point1 = geom.Point(1153461.34, 649950.30)
        point2 = line.placePoint(point1)
        assert "POINT (1153426.8271476042 649411.899502625)" == str(point2)
        point3 = line.placePoint(1153461.34, 649950.30)
        assert "POINT (1153426.8271476042 649411.899502625)" == str(point3)

    def testSubLine(self):
        line = geom.LineString((1137466.548141059, 650434.9943107369),
                               (1175272.4129268457, 648011.541439853),
                               (1185935.6055587344, 632986.1336403737))
        subLine = line.subLine(0.33, 0.67)
        assert "LINESTRING (1156010.153864557 649246.3016361536, 1175115.6870342216 648021.5879714314)" == str(
            subLine)