예제 #1
0
 def create_geospatial_data_from_geonames_json(self, manifest, json_data):
     """ creates and saves geospatial data derived from geonames """
     ok = False
     coords = ''
     lat = False
     lon = False
     ftype = 'Point'
     if 'bbox' in json_data:
         ftype = 'Polygon'
         east = json_data['bbox']['east']
         south = json_data['bbox']['south']
         west = json_data['bbox']['west']
         north = json_data['bbox']['north']
         lat = (south + north) / 2
         lon = (east + west) / 2
         coordinates = []
         cood_inner = []
         cood_inner.append([east,
                            south])
         cood_inner.append([east,
                            north])
         cood_inner.append([west,
                            north])
         cood_inner.append([west,
                            south])
         cood_inner.append([east,
                            south])
         coordinates.append(cood_inner)
         coords = json.dumps(coordinates,
                             indent=4,
                             ensure_ascii=False)
     else:
         coords = ''
         if 'lat' in json_data:
             lat = float(json_data['lat'])
         if 'lng' in json_data:
             lon = float(json_data['lng'])
     if lat is not False and lon is not False:
         # we have OK coodinates, let's save them
         geodata = Geospace()
         geodata.uuid = manifest.uuid
         geodata.project_uuid = manifest.project_uuid
         geodata.source_id = 'geonames-api'
         geodata.item_type = manifest.item_type
         geodata.feature_id = 1
         geodata.meta_type = 'oc-gen:discovey-location'
         geodata.ftype = ftype
         geodata.latitude = lat
         geodata.longitude = lon
         geodata.specificity = self.specifity
         geodata.coordinates = coords
         geodata.note = 'Location data from GeoNames.org'
         geodata.save()
         ok = True
     if ok:
         self.new_geodata += 1
         output = 'New geodata [' + str(self.new_geodata) + '] ' + str(manifest.label)
         output += ' (' + str(manifest.uuid) + ')'
         print(output)
     return ok
예제 #2
0
 def create_geospatial_data_from_geonames_json(self, manifest, json_data):
     """ creates and saves geospatial data derived from geonames """
     ok = False
     coords = ''
     lat = False
     lon = False
     ftype = 'Point'
     if 'bbox' in json_data:
         ftype = 'Polygon'
         east = json_data['bbox']['east']
         south = json_data['bbox']['south']
         west = json_data['bbox']['west']
         north = json_data['bbox']['north']
         lat = (south + north) / 2
         lon = (east + west) / 2
         coordinates = []
         cood_inner = []
         cood_inner.append([east, south])
         cood_inner.append([east, north])
         cood_inner.append([west, north])
         cood_inner.append([west, south])
         cood_inner.append([east, south])
         coordinates.append(cood_inner)
         coords = json.dumps(coordinates, indent=4, ensure_ascii=False)
     else:
         coords = ''
         if 'lat' in json_data:
             lat = float(json_data['lat'])
         if 'lng' in json_data:
             lon = float(json_data['lng'])
     if lat is not False and lon is not False:
         # we have OK coodinates, let's save them
         geodata = Geospace()
         geodata.uuid = manifest.uuid
         geodata.project_uuid = manifest.project_uuid
         geodata.source_id = 'geonames-api'
         geodata.item_type = manifest.item_type
         geodata.feature_id = 1
         geodata.meta_type = 'oc-gen:discovey-location'
         geodata.ftype = ftype
         geodata.latitude = lat
         geodata.longitude = lon
         geodata.specificity = self.specifity
         geodata.coordinates = coords
         geodata.note = 'Location data from GeoNames.org'
         geodata.save()
         ok = True
     if ok:
         self.new_geodata += 1
         output = 'New geodata [' + str(self.new_geodata) + '] ' + str(
             manifest.label)
         output += ' (' + str(manifest.uuid) + ')'
         print(output)
     return ok
예제 #3
0
 def make_geo_obj(self, feature_id, lon, lat, coords=False):
     geo_obj = Geospace()
     geo_obj.uuid = self.project_uuid
     geo_obj.project_uuid = self.project_uuid
     geo_obj.source_id = 'Project metadata summary'
     geo_obj.item_type = 'projects'
     geo_obj.feature_id = feature_id
     geo_obj.meta_type = 'oc-gen:geo-coverage'
     if coords is False:
         geo_obj.ftype = 'Point'
         geo_obj.coordinates = ''
     else:
         geo_obj.ftype = 'Polygon'
         geo_obj.coordinates = json.dumps(coords, ensure_ascii=False)
     geo_obj.latitude = lat
     geo_obj.longitude = lon
     geo_obj.specificity = 0
     geo_obj.note = 'Project geographic coverage \
                     summarized from geospatial data \
                     describing subjects published \
                     with this project.'
     return geo_obj
예제 #4
0
 def make_geo_obj(self, feature_id, lon, lat, coords=False):
     geo_obj = Geospace()
     geo_obj.uuid = self.project_uuid
     geo_obj.project_uuid = self.project_uuid
     geo_obj.source_id = 'Project metadata summary'
     geo_obj.item_type = 'projects'
     geo_obj.feature_id = feature_id
     geo_obj.meta_type = 'oc-gen:geo-coverage'
     if coords is False:
         geo_obj.ftype = 'Point'
         geo_obj.coordinates = ''
     else:
         geo_obj.ftype = 'Polygon'
         geo_obj.coordinates = json.dumps(coords, ensure_ascii=False)
     geo_obj.latitude = lat
     geo_obj.longitude = lon
     geo_obj.specificity = self.project_specificity
     geo_obj.note = 'Project geographic coverage \
                     summarized from geospatial data \
                     describing subjects published \
                     with this project.'
     return geo_obj