def shaperead(fn, encoding=None): ''' Returns a layer readed from a shape file. :param fn: (*string*) The shape file name (.shp). :param encoding: (*string*) Encoding :returns: (*MILayer*) The created layer. ''' if not fn.endswith('.shp'): fn = fn + '.shp' if not os.path.exists(fn): fn = os.path.join(migl.get_map_folder(), fn) if os.path.exists(fn): try: if encoding is None: encoding = IOUtil.encodingDetectShp(fn) if encoding == 'ISO8859_1': encoding = 'UTF-8' layer = MILayer(MapDataManage.readMapFile_ShapeFile(fn, encoding)) if not layer.legend() is None: lb = layer.legend().getLegendBreaks()[0] if lb.getBreakType() == BreakTypes.PolygonBreak: lb.setDrawFill(False) return layer except: raise else: print 'File not exists: ' + fn raise
def geoshow(self, layer, **kwargs): ''' Plot a layer in 3D axes. :param layer: (*MILayer*) The layer to be plotted. :returns: Graphics. ''' ls = kwargs.pop('symbolspec', None) offset = kwargs.pop('offset', 0) xshift = kwargs.pop('xshift', 0) if isinstance(layer, basestring): fn = layer if not fn.endswith('.shp'): fn = fn + '.shp' if not os.path.exists(fn): fn = os.path.join(migl.get_map_folder(), fn) if os.path.exists(fn): encoding = kwargs.pop('encoding', None) layer = migeo.shaperead(fn, encoding) else: raise IOError('File not exists: ' + fn) layer = layer.layer if layer.getLayerType() == LayerTypes.VectorLayer: if ls is None: ls = layer.getLegendScheme() if layer.getLegendScheme().getBreakNum() == 1: lb = layer.getLegendScheme().getLegendBreaks().get(0) btype = lb.getBreakType() geometry = 'point' if btype == BreakTypes.PolylineBreak: geometry = 'line' elif btype == BreakTypes.PolygonBreak: geometry = 'polygon' if not kwargs.has_key('facecolor'): kwargs['facecolor'] = None if not kwargs.has_key('edgecolor'): kwargs['edgecolor'] = 'k' lb, isunique = plotutil.getlegendbreak(geometry, **kwargs) ls.getLegendBreaks().set(0, lb) else: plotutil.setlegendscheme(ls, **kwargs) layer.setLegendScheme(ls) graphics = GraphicFactory.createGraphicsFromLayer( layer, offset, xshift) else: interpolation = kwargs.pop('interpolation', None) graphics = JOGLUtil.createTexture(self.figure.getGL2(), layer, offset, xshift, interpolation) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) return graphics
def georead(fn): ''' Returns a layer readed from a supported geo-data file. :param fn: (*string*) The supported geo-data file name (shape file, wmp, geotiff, image, bil...). :returns: (*MILayer*) The created layer. ''' if not os.path.exists(fn): fn = os.path.join(migl.get_map_folder(), fn) if os.path.exists(fn): try: layer = MILayer(MapDataManage.loadLayer(fn)) if not layer.legend() is None: lb = layer.legend().getLegendBreaks()[0] if lb.getBreakType() == BreakTypes.PolygonBreak: lb.setDrawFill(False) return layer except: raise else: print 'File not exists: ' + fn raise IOError