def features_geoJSON(self, as_json=True, using_style_template=True): geojson = SortedDict() geojson["type"] = "FeatureCollection" geojson["properties"] = dict(id=self.id) geojson["features"] = [n.geoJSON(as_json=False, using_style_template=using_style_template) for n in self.feature_set.all()] return clean_dumps(geojson, indent=2) if as_json else geojson
def grid_geoJSON(self, as_json=True): """ Return geoJSON of grid for export """ geojson = SortedDict() geojson["type"] = "FeatureCollection" geojson["features"] = [json.loads(aoi.grid_geoJSON()) for aoi in self.aois.all()] return clean_dumps(geojson) if as_json else geojson
def to_json(self): icon = "" if self.icon: icon = "/images/"+str(self.icon) return clean_dumps(dict(id=self.id, properties=self.properties, category=self.category, order=self.order, name=self.name, type=self.type, style=self.style, icon=icon))
def aois_envelope_by_job(self): jobs = [] for job in self.jobs: if job.aois.count(): job_envelope = job.aois_envelope() envelope_string = job_envelope.json if envelope_string: job_poly = json.loads(envelope_string) job_poly['properties'] = {"job_id": str(job.id), "link": str(job.get_absolute_url()), "name": str(job.name)} jobs.append(job_poly) return clean_dumps(jobs, ensure_ascii=True)
def geoJSON(self, as_json=True, using_style_template=True): """ Returns geoJSON of the feature. Try to conform to https://github.com/mapbox/simplestyle-spec/tree/master/1.0.0 """ properties_main = self.properties or {} properties_built = dict( id=self.id, status=self.status, analyst=self.analyst.username, created_at=datetime.strftime(self.created_at, '%Y-%m-%dT%H:%M:%S%Z'), updated_at=datetime.strftime(self.updated_at, '%Y-%m-%dT%H:%M:%S%Z'), ) properties_template = self.template.properties or {} # properties_template can return a list from it's backing model, make sure we get the Dict if type(properties_template) == types.ListType: properties_template = properties_template[0] # srj: if using_style_template set, we're styling object from its feature id, else we'll # just use the style properties (which should already be included if defined for feature) # (we may want to set some defaults later on to make sure) if using_style_template: properties_built['template'] = self.template.id if hasattr( self.template, "id") else None properties = dict(properties_built.items() + properties_main.items() + properties_template.items()) feature_type = FeatureType.objects.get(id=self.template.id) geojson = SortedDict() geojson["type"] = "Feature" geojson["properties"] = properties geojson["geometry"] = json.loads(self.the_geom.json) if feature_type and using_style_template: geojson["style"] = feature_type.style_to_geojson() else: geojson["style"] = feature_type.style if (as_json): return clean_dumps(geojson) else: for key in properties: if isinstance(properties[key], str) or isinstance( properties[key], unicode): properties[key] = properties[key].replace( '<', '<l').replace('>', '>').replace( "javascript:", "j_script-") return geojson
def to_json(self): icon = "" if self.icon: icon = "/images/" + str(self.icon) return clean_dumps( dict(id=self.id, properties=self.properties, category=self.category, order=self.order, name=self.name, type=self.type, style=self.style, icon=icon))
def grid_geoJSON(self): """ Return geoJSON of workcells for export """ if self.id is None: self.id = 1 geojson = SortedDict() geojson["type"] = "Feature" geojson["properties"] = dict(id=self.id, priority=self.priority, status=self.status) geojson["geometry"] = json.loads(self.polygon.json) return clean_dumps(geojson)
def properties_json(self): """ Returns json of the feature properties. """ if self.id is None: self.id = 1 properties_main = self.properties or {} properties_built = dict( status=self.status, analyst=(self.analyst.username if self.analyst is not None else 'Unassigned'), priority=self.priority) prop_json = dict(properties_built.items() + properties_main.items()) return clean_dumps(prop_json)
def geoJSON(self, as_json=True, using_style_template=True): """ Returns geoJSON of the feature. Try to conform to https://github.com/mapbox/simplestyle-spec/tree/master/1.0.0 """ properties_main = self.properties or {} properties_built = dict(id=self.id, status=self.status, analyst=self.analyst.username, created_at=datetime.strftime(self.created_at, '%Y-%m-%dT%H:%M:%S%Z'), updated_at=datetime.strftime(self.updated_at, '%Y-%m-%dT%H:%M:%S%Z'), ) properties_template = self.template.properties or {} # properties_template can return a list from it's backing model, make sure we get the Dict if type(properties_template) == types.ListType: properties_template = properties_template[0] # srj: if using_style_template set, we're styling object from its feature id, else we'll # just use the style properties (which should already be included if defined for feature) # (we may want to set some defaults later on to make sure) if using_style_template: properties_built['template'] = self.template.id if hasattr(self.template, "id") else None properties = dict(properties_built.items() + properties_main.items() + properties_template.items()) feature_type = FeatureType.objects.get(id=self.template.id) geojson = SortedDict() geojson["type"] = "Feature" geojson["properties"] = properties geojson["geometry"] = json.loads(self.the_geom.json) if feature_type and using_style_template: geojson["style"] = feature_type.style_to_geojson() else: geojson["style"] = feature_type.style if(as_json): return clean_dumps(geojson) else: for key in properties: if isinstance(properties[key],str) or isinstance(properties[key], unicode): properties[key] = properties[key].replace('<', '<l').replace('>', '>').replace("javascript:", "j_script-") return geojson
def geoJSON(self): """ Returns geoJSON of the feature. """ if self.id is None: self.id = 1 geojson = SortedDict() geojson["type"] = "Feature" geojson["properties"] = dict( id=self.id, status=self.status, analyst=(self.analyst.username if self.analyst is not None else 'None'), assignee=self.assignee_name, priority=self.priority, delete_url=reverse('aoi-deleter', args=[self.id])) geojson["geometry"] = json.loads(self.polygon.json) geojson["properties"]["absolute_url"] = self.get_absolute_url() return clean_dumps(geojson)
def to_json(self): obj = self.to_object() return clean_dumps(obj)
def all_map_layers_json(self): map_services = list() for layer in Layer.objects.all(): if not layer.disabled: map_services.append(layer.layer_json()) return clean_dumps(map_services)
def style_json(self): return clean_dumps(self.style)