Exemplo n.º 1
0
def makeshapes(x, y, type=None):
    """
    Make shapes by x and y coordinates.
    
    :param x: (*array_like*) X coordinates.
    :param y: (*array_like*) Y coordinates.
    :param type: (*string*) Shape type [point | line | polygon].
    
    :returns: Shapes
    """
    shapes = []   
    if isinstance(x, (int, float)):
        shape = PointShape()
        shape.setPoint(PointD(x, y))
        shapes.append(shape)    
    else:
        if not isinstance(x, list):
            x = x.asarray()
        if not isinstance(y, list):
            y = y.asarray()
        if type == 'point':
            shapes = ShapeUtil.createPointShapes(x, y)
        elif type == 'line':
            shapes = ShapeUtil.createPolylineShapes(x, y)
        elif type == 'polygon':
            shapes = ShapeUtil.createPolygonShapes(x, y)
    return shapes    
Exemplo n.º 2
0
def makeshapes(x, y, type=None, z=None, m=None):
    """
    Make shapes by x and y coordinates.
    
    :param x: (*array_like*) X coordinates.
    :param y: (*array_like*) Y coordinates.    
    :param type: (*string*) Shape type [point | line | polygon].
    :param z: (*array_like*) Z coordinates.
    :param m: (*array_like*) M coordinates.
    
    :returns: Shapes
    """
    shapes = []   
    if isinstance(x, (int, float)):
        shape = PointShape()
        shape.setPoint(PointD(x, y))
        shapes.append(shape)    
    else:
        x = minum.asarray(x).array
        y = minum.asarray(y).array
        if not z is None:            
            if m is None:
                m = minum.zeros(len(z)).array
            else:
                m = minum.asarray(m)
            z = minum.asarray(z)
        if type == 'point':
            if z is None:
                shapes = ShapeUtil.createPointShapes(x, y)
            else:
                shapes = ShapeUtil.createPointShapes(x, y, z, m)
        elif type == 'line':
            if z is None:
                shapes = ShapeUtil.createPolylineShapes(x, y)
            else:
                shapes = ShapeUtil.createPolylineShapes(x, y, z, m)
        elif type == 'polygon':
            if z is None:
                shapes = ShapeUtil.createPolygonShapes(x, y)
            else:
                shapes = ShapeUtil.createPolygonShape(x, y, z, m)
    return shapes   
    
Exemplo n.º 3
0
def makeshapes(x, y, type=None, z=None, m=None):
    """
    Make shapes by x and y coordinates.
    
    :param x: (*array_like*) X coordinates.
    :param y: (*array_like*) Y coordinates.    
    :param type: (*string*) Shape type [point | line | polygon].
    :param z: (*array_like*) Z coordinates.
    :param m: (*array_like*) M coordinates.
    
    :returns: Shapes
    """
    shapes = []   
    if isinstance(x, (int, float)):
        shape = PointShape()
        shape.setPoint(PointD(x, y))
        shapes.append(shape)    
    else:
        x = minum.asarray(x).array
        y = minum.asarray(y).array
        if not z is None:            
            if m is None:
                m = minum.zeros(len(z)).array
            else:
                m = minum.asarray(m).array
            z = minum.asarray(z).array
        if type == 'point':
            if z is None:
                shapes = ShapeUtil.createPointShapes(x, y)
            else:
                shapes = ShapeUtil.createPointShapes(x, y, z, m)
        elif type == 'line':
            if z is None:
                shapes = ShapeUtil.createPolylineShapes(x, y)
            else:
                shapes = ShapeUtil.createPolylineShapes(x, y, z, m)
        elif type == 'polygon':
            if z is None:
                shapes = ShapeUtil.createPolygonShapes(x, y)
            else:
                shapes = ShapeUtil.createPolygonShape(x, y, z, m)
    return shapes   
    
Exemplo n.º 4
0
nLayer.setVisible( True)
fieldName = "Inside"
nLayer.editAddField(fieldName, DataTypes.String)

print 'The points inside Tibet are:'
tibetArea = countryLayer.getShapes()[107]

sLon = 110.05
sLat = 35.85
delt = 0.1
print 'x     y      long    lat'
for i in range(0, 120):
  lon = sLon + i * delt
  for j in range(0, 70):
    
    aPS = PointShape()    
    lat = sLat + j * delt
    #print lon, lat
    aPoint = PointD(lon, lat)
    aPS.setPoint( aPoint)
    shapeNum = nLayer.getShapeNum()
    #print "Shape Number: %d" % (shapeNum)
    nLayer.editInsertShape(aPS, shapeNum)
    if GeoComputation.pointInPolygon(tibetArea, aPoint):
      nLayer.editCellValue(fieldName, shapeNum, "Y")
      print i+1, '  ',  j+1, '   ',  "%5.2f  %5.2f" % (lon, lat)
    else:
      nLayer.editCellValue(fieldName, shapeNum, "N")

#print "Layer Name: %s" % (nLayer.getLayerName())
mapFrame.addLayer(nLayer)