def get_context(self, name, value, attrs): # If a string reaches here (via a validation error on another # field) then just reconstruct the Geometry. if value and isinstance(value, str): value = self.deserialize(value) if value: # Check that srid of value and map match if value.srid and value.srid != self.map_srid: try: ogr = value.ogr ogr.transform(self.map_srid) value = ogr except gdal.GDALException as err: logger.error( "Error transforming geometry from srid '%s' to srid '%s' (%s)", value.srid, self.map_srid, err) if attrs is None: attrs = {} context = self.build_attrs( self.attrs, dict( name=name, module='geodjango_%s' % name.replace('-', '_'), # JS-safe serialized=self.serialize(value), geom_type=gdal.OGRGeomType(self.attrs['geom_type']), STATIC_URL=settings.STATIC_URL, LANGUAGE_BIDI=translation.get_language_bidi(), **attrs)) return context
def get_context(self, name, value, attrs): context = super().get_context(name, value, attrs) # If a string reaches here (via a validation error on another # field) then just reconstruct the Geometry. if value and isinstance(value, str): value = self.deserialize(value) if value: # Check that srid of value and map match if value.srid and value.srid != self.map_srid: try: ogr = value.ogr ogr.transform(self.map_srid) value = ogr except gdal.GDALException as err: logger.error( "Error transforming geometry from srid '%s' to srid '%s' (%s)", value.srid, self.map_srid, err) context.update( self.build_attrs( self.attrs, { 'name': name, 'module': 'geodjango_%s' % name.replace('-', '_'), # JS-safe 'serialized': self.serialize(value), 'geom_type': gdal.OGRGeomType(self.attrs['geom_type']), 'STATIC_URL': settings.STATIC_URL, 'LANGUAGE_BIDI': translation.get_language_bidi(), **(attrs or {}), })) return context
def render(self, name, value, attrs=None): # If a string reaches here (via a validation error on another # field) then just reconstruct the Geometry. if isinstance(value, six.string_types): value = self.deserialize(value) if isinstance(value, dict): value = GEOSGeometry(json.dumps(value), srid=self.map_srid) if value: # Check that srid of value and map match if value.srid != self.map_srid: try: ogr = value.ogr ogr.transform(self.map_srid) value = ogr except gdal.OGRException as err: logger.error( "Error transforming geometry from srid '%s' to srid " "'%s' (%s)" % (value.srid, self.map_srid, err)) context = self.build_attrs( attrs, name=name, module='geodjango_%s' % name.replace('-', '_'), # JS-safe serialized=self.serialize(value), geom_type=gdal.OGRGeomType(self.attrs['geom_type']), STATIC_URL=settings.STATIC_URL, LANGUAGE_BIDI=translation.get_language_bidi(), ) return loader.render_to_string(self.template_name, context)
def get_context_data(self): ctx = super(BaseGeometryWidget, self).get_context_data() for key in ('is_polygon', 'is_linestring', 'is_point', 'is_collection'): ctx[key] = getattr(self, key) ctx['geom_type'] = gdal.OGRGeomType(self.geom_type) for key in self.map_attrs: ctx[key] = getattr(self, key) if self.geom_type == 'GEOMETRYCOLLECTION': ctx['geom_type'] = 'Collection' return ctx
def get_context(self, name, value, attrs=None): # If a string reaches here (via a validation error on another # field) then just reconstruct the Geometry. if isinstance(value, six.string_types): value = self.deserialize(value) if value: # Check that srid of value and map match if value.srid != self.map_srid: try: ogr = value.ogr ogr.transform(self.map_srid) value = ogr except gdal.GDALException as err: logger.error( "Error transforming geometry from srid '%s' to srid " "'%s' (%s)", value.srid, self.map_srid, err) if not attrs: attrs = {} attrs.update({ "name": name, "module": 'geodjango_%s' % name.replace('-', '_'), # JS-safe "serialized": self.serialize(value), "geom_type": gdal.OGRGeomType(self.attrs['geom_type']), "STATIC_URL": settings.STATIC_URL, "LANGUAGE_BIDI": translation.get_language_bidi(), }) context = self.build_attrs( self.attrs or {}, attrs ) # fallback if no id if 'id' not in context: context['id'] = name return context
def get_context(self, name, value, attrs): context = super().get_context(name, value, attrs) # If a string reaches here (via a validation error on another # field) then just reconstruct the Geometry. if value and isinstance(value, str): value = self.deserialize(value) if value: # Check that srid of value and map match if value.srid and value.srid != self.map_srid: try: ogr = value.ogr ogr.transform(self.map_srid) value = ogr except gdal.GDALException as err: logger.error( "Error transforming geometry from srid '%s' to srid '%s' (%s)", value.srid, self.map_srid, err, ) geom_type = gdal.OGRGeomType(self.attrs["geom_type"]).name context.update( self.build_attrs( self.attrs, { "name": name, "module": "geodjango_%s" % name.replace("-", "_"), # JS-safe "serialized": self.serialize(value), "geom_type": "Geometry" if geom_type == "Unknown" else geom_type, "STATIC_URL": settings.STATIC_URL, "LANGUAGE_BIDI": translation.get_language_bidi(), **(attrs or {}), }, )) return context