def getCoordinatesByAddress(address,crs=None): # In: Country, City, Postal Address or Parts of it # Target Coordinate Reference System as EPSG Code # Out: dict of all informations delivered by googlemaps if isinstance(address, unicode): address = address.encode('utf-8') urlParams = {'q': address, 'format': 'json', 'addressdetails': '1', } url='http://nominatim.openstreetmap.org/search?'+urllib.urlencode(urlParams) response = urllib2.urlopen(url) result = json.load(response) #print result['results'] # try: addrlist = [] for addrrecord in result: dataset = {} dataset['latitude'] = addrrecord['lat'] dataset['longitude'] = addrrecord['lon'] if crs: targetCRS = QgsCoordinateReferenceSystem(crs, QgsCoordinateReferenceSystem.EpsgCrsId) googleMapsCRS = QgsCoordinateReferenceSystem(4326, QgsCoordinateReferenceSystem.EpsgCrsId) location = QgsCoordinateTransform(googleMapsCRS, targetCRS).transform(QgsPoint(dataset['longitude'], dataset['latitude'])) dataset['latitude'] = location.y() dataset['longitude'] = location.x() addrlist.append(complete_google_dataset(dataset)) # except: # return [] return addrlist
def createURL(self, lat, long): point = QgsPoint(long, lat) pt3857 = QgsCoordinateTransform( QgsCoordinateReferenceSystem(4326), QgsCoordinateReferenceSystem(3857) ).transform(point) url = "http://pkk5.rosreestr.ru/#x=%.9f&y=%.9f&z=19&text=%s %s&type=1&app=search&opened=1" % ( pt3857.x(), pt3857.y(), str("{0:.6f}".format(lat)).replace('.', ','), str("{0:.6f}".format(long)).replace('.', ',') ) return url
def getCoordinatesByAddress(address, crs=None): # In: Country, City, Postal Address or Parts of it # Target Coordinate Reference System as EPSG Code # Out: dict of all informations delivered by googlemaps if isinstance(address, unicode): address = address.encode('utf-8') urlParams = { 'q': address, 'format': 'json', 'addressdetails': '1', } url = 'http://nominatim.openstreetmap.org/search?' + urllib.urlencode( urlParams) response = urllib2.urlopen(url) result = json.load(response) #print result['results'] # try: addrlist = [] for addrrecord in result: dataset = {} dataset['latitude'] = addrrecord['lat'] dataset['longitude'] = addrrecord['lon'] if crs: targetCRS = QgsCoordinateReferenceSystem( crs, QgsCoordinateReferenceSystem.EpsgCrsId) googleMapsCRS = QgsCoordinateReferenceSystem( 4326, QgsCoordinateReferenceSystem.EpsgCrsId) location = QgsCoordinateTransform( googleMapsCRS, targetCRS).transform( QgsPoint(dataset['longitude'], dataset['latitude'])) dataset['latitude'] = location.y() dataset['longitude'] = location.x() addrlist.append(complete_google_dataset(dataset)) # except: # return [] return addrlist