def inpolygon(x, y, polygon): ''' Check if x/y points are inside a polygon or not. :param x: (*array_like*) X coordinate of the points. :param y: (*array_like*) Y coordinate of the points. :param polygon: (*PolygonShape list*) The polygon list. :returns: (*boolean array*) Inside or not. ''' if isinstance(x, numbers.Number): return GeoComputation.pointInPolygon(polygon, x, y) if isinstance(x, (list, tuple)): x = minum.array(x) if isinstance(y, (list, tuple)): y = minum.array(y) if isinstance(polygon, tuple): x_p = polygon[0] y_p = polygon[1] if isinstance(x_p, (list, tuple)): x_p = minum.array(x_p) if isinstance(y_p, (list, tuple)): y_p = minum.array(y_p) return MIArray(ArrayMath.inPolygon(x.array, y.array, x_p.array, y_p.array)) else: if isinstance(polygon, MILayer): polygon = polygon.shapes() elif isinstance(polygon, PolygonShape): polygon = [polygon] return MIArray(ArrayMath.inPolygon(x.array, y.array, polygon))
def inpolygon(x, y, polygon): ''' Judge if a point is inside a polygon or not. :param x: (*float*) X coordinate of the point. :param y: (*float*) Y coordinate of the point. :param polygon: (*PolygonShape*) The polygon. :returns: (*boolean*) Inside or not. ''' return GeoComputation.pointInPolygon(polygon, x, y)
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) #nLayer.saveFile() #print 'Finished!'