def import_bounding_box(self, layer): """Get bounding box information from the layer; layer is an instance of owslib.wms.ContentMetaData.""" logger.info("BBOX1: " + repr(layer.boundingBoxWGS84)) logger.info("BBOX2: " + repr(layer.boundingBox)) minx = miny = maxx = maxy = srs = None if layer.boundingBoxWGS84: minx, miny, maxx, maxy = layer.boundingBoxWGS84 srs = 'EPSG:4326' else: minx, miny, maxx, maxy, srs = layer.boundingBox logger.info("SRS: " + srs) if srs == "ESPG:900913": # Yay! pass elif srs == "EPSG:28992": minx, miny = coordinates.rd_to_google(minx, miny) maxx, maxy = coordinates.rd_to_google(maxx, maxy) elif srs == "EPSG:4326": minx, miny = coordinates.wgs84_to_google(minx, miny) maxx, maxy = coordinates.wgs84_to_google(maxx, maxy) else: self.bbox = None return self.bbox = ",".join(str(coord) for coord in (minx, miny, maxx, maxy)) logger.info("RESULT: " + self.bbox)
def extent(self, identifiers=None): """Return extent.""" north = None south = None east = None west = None wgs0coord_x, wgs0coord_y = coordinates.rd_to_wgs84(0.0, 0.0) for info in self._timeseries(): x = info['rd_x'] y = info['rd_y'] # Ignore rd coordinates (0, 0). if (abs(x - wgs0coord_x) > EPSILON or abs(y - wgs0coord_y) > EPSILON): if x > east or east is None: east = x if x < west or west is None: west = x if y < south or south is None: south = y if y > north or north is None: north = y west_transformed, north_transformed = coordinates.rd_to_google( west, north) east_transformed, south_transformed = coordinates.rd_to_google( east, south) return { 'north': north_transformed, 'west': west_transformed, 'south': south_transformed, 'east': east_transformed}
def extent(self, identifiers=None): "Return extent in Google projection." west, south, east, north = Hydrovak.objects.filter( project__slug=self.project_slug).only("the_geom").extent() west, south = rd_to_google(west, south) east, north = rd_to_google(east, north) return {'west': west, 'south': south, 'east': east, 'north': north}
def extent(self, identifiers=None): """ Returns extent {'west':.., 'south':.., 'east':.., 'north':..} in google projection. None for each key means unknown. """ if not self.project or not self.contractor: return {'west': None, 'south': None, 'east': None, 'north': None} locations = Location.objects.filter( project=self.project, scheduledmeasurement__contractor=self.contractor) if self.measurement_type: locations = locations.filter( scheduledmeasurement__measurement_type=self.measurement_type) if not locations.exists(): return {'west': None, 'south': None, 'east': None, 'north': None} west, south, east, north = locations.only("the_geom").extent() west, south = rd_to_google(west, south) east, north = rd_to_google(east, north) return {'west': west, 'south': south, 'east': east, 'north': north}
def post(self, request, *args, **kwargs): post = request.POST message_list = ["result: ", ] try: google_x = float(post['google_x']) google_y = float(post['google_y']) c_rd = coordinates.google_to_rd(google_x, google_y) message_list.append('Google (%s, %s) = RD (%s, %s)' % ( google_x, google_y, c_rd[0], c_rd[1])) c_wgs84 = coordinates.google_to_wgs84(google_x, google_y) message_list.append('Google (%s, %s) = WGS84 (%s, %s)' % ( google_x, google_y, c_wgs84[0], c_wgs84[1])) except: pass try: rd_x = float(post['rd_x']) rd_y = float(post['rd_y']) c_google = coordinates.rd_to_google(rd_x, rd_y) message_list.append('RD (%s, %s) = Google (%s, %s)' % ( rd_x, rd_y, c_google[0], c_google[1])) c_wgs84 = coordinates.rd_to_wgs84(rd_x, rd_y) message_list.append('RD (%s, %s) = WGS84 (%s, %s)' % ( rd_x, rd_y, c_wgs84[0], c_wgs84[1])) except: pass try: wgs84_x = float(post['wgs84_x']) wgs84_y = float(post['wgs84_y']) c_google = coordinates.wgs84_to_google(wgs84_x, wgs84_y) message_list.append('WGS84 (%s, %s) = Google (%s, %s)' % ( wgs84_x, wgs84_y, c_google[0], c_google[1])) c_rd = coordinates.wgs84_to_rd(wgs84_x, wgs84_y) message_list.append('WGS84 (%s, %s) = RD (%s, %s)' % ( wgs84_x, wgs84_y, c_rd[0], c_rd[1])) except: pass self.message = '<br/>'.join(message_list) return super(ConvertView, self).get(request, *args, **kwargs)
def google_coords(self): return coordinates.rd_to_google(self.x, self.y)