def project(x, y, fromproj=KnownCoordinateSystems.geographic.world.WGS1984, toproj=KnownCoordinateSystems.geographic.world.WGS1984): """ Project geographic coordinates from one projection to another. :param x: (*array_like*) X coordinate values for projection. :param y: (*array_like*) Y coordinate values for projection. :param fromproj: (*ProjectionInfo*) From projection. Default is longlat projection. :param toproj: (*ProjectionInfo*) To projection. Default is longlat projection. :returns: (*array_like*, *array_like*) Projected geographic coordinates. """ if isinstance(fromproj, str): fromproj = ProjectionInfo(fromproj) if isinstance(toproj, str): toproj = ProjectionInfo(toproj) if isinstance(x, (tuple, list)): x = array(x) if isinstance(y, (tuple, list)): y = array(y) if isinstance(x, MIArray): outxy = ArrayUtil.reproject(x.asarray(), y.asarray(), fromproj, toproj) return MIArray(outxy[0]), MIArray(outxy[1]) else: inpt = PointD(x, y) outpt = Reproject.reprojectPoint(inpt, fromproj, toproj) return outpt.X, outpt.Y
def projinfo(proj4string=None, proj='longlat', **kwargs): """ Create a projection object with Proj.4 parameters (http://proj4.org/) :param proj4string: (*string*) Proj.4 projection string. :param proj: (*string*) Projection name. :param lat_0: (*float*) Latitude of origin. :param lon_0: (*float*) Central meridian. :param lat_1: (*float*) Latitude of first standard paralle. :param lat_2: (*float*) Latitude of second standard paralle. :param lat_ts: (*float*) Latitude of true scale. :param k: (*float*) Scaling factor. :param x_0: (*float*) False easting. :param y_0: (*float*) False northing. :param h: (*float*) Height from earth surface. :returns: (*ProjectionInfo*) ProjectionInfo object. """ if not proj4string is None: return ProjectionInfo(proj4string) if proj == 'longlat' and len(kwargs) == 0: return KnownCoordinateSystems.geographic.world.WGS1984 origin = kwargs.pop('origin', (0, 0, 0)) lat_0 = origin[0] lon_0 = origin[1] lat_0 = kwargs.pop('lat_0', lat_0) lon_0 = kwargs.pop('lon_0', lon_0) lat_ts = kwargs.pop('truescalelat', 0) lat_ts = kwargs.pop('lat_ts', lat_ts) k = kwargs.pop('scalefactor', 1) k = kwargs.pop('k', k) paralles = kwargs.pop('paralles', (30, 60)) lat_1 = paralles[0] if len(paralles) == 2: lat_2 = paralles[1] else: lat_2 = lat_1 lat_1 = kwargs.pop('lat_1', lat_1) lat_2 = kwargs.pop('lat_2', lat_2) x_0 = kwargs.pop('falseeasting', 0) y_0 = kwargs.pop('falsenorthing', 0) x_0 = kwargs.pop('x_0', x_0) y_0 = kwargs.pop('y_0', y_0) h = kwargs.pop('h', None) projstr = '+proj=' + proj \ + ' +lat_0=' + str(lat_0) \ + ' +lon_0=' + str(lon_0) \ + ' +lat_1=' + str(lat_1) \ + ' +lat_2=' + str(lat_2) \ + ' +lat_ts=' + str(lat_ts) \ + ' +k=' + str(k) \ + ' +x_0=' + str(x_0) \ + ' +y_0=' + str(y_0) if not h is None: projstr = projstr + ' +h=' + str(h) return ProjectionInfo(projstr)
def __init__(self, axes=None, figure=None, **kwargs): self.figure = figure if axes is None: projinfo = kwargs.pop('projinfo', None) if projinfo == None: proj = kwargs.pop('proj', 'longlat') origin = kwargs.pop('origin', (0, 0, 0)) lat_0 = origin[0] lon_0 = origin[1] lat_0 = kwargs.pop('lat_0', lat_0) lon_0 = kwargs.pop('lon_0', lon_0) lat_ts = kwargs.pop('truescalelat', 0) lat_ts = kwargs.pop('lat_ts', lat_ts) k = kwargs.pop('scalefactor', 1) k = kwargs.pop('k', k) paralles = kwargs.pop('paralles', (30, 60)) lat_1 = paralles[0] if len(paralles) == 2: lat_2 = paralles[1] else: lat_2 = lat_1 lat_1 = kwargs.pop('lat_1', lat_1) lat_2 = kwargs.pop('lat_2', lat_2) x_0 = kwargs.pop('falseeasting', 0) y_0 = kwargs.pop('falsenorthing', 0) x_0 = kwargs.pop('x_0', x_0) y_0 = kwargs.pop('y_0', y_0) h = kwargs.pop('h', 0) projstr = '+proj=' + proj \ + ' +lat_0=' + str(lat_0) \ + ' +lon_0=' + str(lon_0) \ + ' +lat_1=' + str(lat_1) \ + ' +lat_2=' + str(lat_2) \ + ' +lat_ts=' + str(lat_ts) \ + ' +k=' + str(k) \ + ' +x_0=' + str(x_0) \ + ' +y_0=' + str(y_0) \ + ' +h=' + str(h) projinfo = ProjectionInfo(projstr) mapview = MapView(projinfo) self.axes = MapPlot(mapview) else: self.axes = axes self.axestype = 'map' self.proj = self.axes.getProjInfo()
labset.setYOffset(15) cityLayer.addLabels() mapFrame.addLayer(cityLayer) #---- Add South China Sea aMapFrame = MapFrame() aLayoutMap = LayoutMap(aMapFrame) aLayoutMap.setDrawGridLabel(False) aLayoutMap.setDrawGridTickLine(False) aLayoutMap.setLeft(40) aLayoutMap.setTop(350) aLayoutMap.setWidth(85) aLayoutMap.setHeight(109) mapLayout.addElement(aLayoutMap) aMapFrame.addLayer(bou1Layer_1) aProjInfo = ProjectionInfo("+proj=lcc+lat_1=25+lat_2=47+lon_0=105") aMapFrame.getMapView().projectLayers(aProjInfo) aMapFrame.getMapView().zoomToExtentLonLatEx(Extent(106.5,122.5,1,23)) #---- Project mapview print 'Project mapview...' projStr = '+proj=lcc+lat_1=25+lat_2=47+lon_0=105' projInfo = ProjectionInfo(projStr) mapView.projectLayers(projInfo) extent = Extent(78,130,15,53) mapView.zoomToExtentLonLatEx(extent) #---- Create MeteoDataInfo object mdi = MeteoDataInfo() #---- Set start/end time
pressLayer = DrawMeteoData.createShadedLayer(gdata, ls, 'Pressure', 'PS', True) #---- Add layer mapFrame.addLayer(pressLayer) #--- Move pressure layer to bottom mapFrame.moveLayer(pressLayer, 0) #---- Add title title = mapLayout.addText('MeteoInfo script demo - Projection', 350, 50, 'Arial', 16) #---- Project mapview print 'Project mapview...' projStr = '+proj=moll +lon_0=105' projInfo = ProjectionInfo(projStr) mapFrame.getMapView().projectLayers(projInfo) #---- Set mapframe mapFrame.setDrawNeatLine(False) mapFrame.setDrawGridLine(True) mapFrame.setDrawGridLabel(False) mapFrame.setGridLabelPosition(GridLabelPosition.All) mapFrame.setGridXDelt(30) mapFrame.setGridYDelt(30) #---- Add legend legend = mapLayout.addLegend(150, 420) legend.setLegendStyle(LegendStyles.Bar_Horizontal) legend.setLegendLayer(pressLayer)