Skip to content

Instantly share code, notes, and snippets.

@Moult Moult/input
Last active Jun 17, 2018

Embed
What would you like to do?
Query LPI for address data
-33.77887533975928, 151.06648295849564
-33.77889317514952, 151.06632202595472
-33.77896451667338, 151.0661557289958
-33.778819604140814, 151.0659357878566
-33.77903139929803, 151.0659599277377
-33.77892438707354, 151.06576680868864
-33.778991269729524, 151.06563001602888
-33.77869921508115, 151.06573998659852
-33.77857882585231, 151.06628715723753
-33.77847627193128, 151.06701135367157
-33.778340276324926, 151.06752365559342
-33.77859666130429, 151.06777310103178
-33.77861895561406, 151.06758266419175
-33.77863679105767, 151.06741100281477
-33.77879062160489, 151.06723397701984
-33.778674691363086, 151.0670542690158
-33.77881737471531, 151.06685846775773
import json
from urllib.request import urlopen
from osgeo import ogr
from osgeo import osr
print('"latitude";"longitude";"addr:housenumber";"addr:street"')
with open('input') as f:
lines = f.readlines()
for line in lines:
lat, long = line.split(', ')
source = osr.SpatialReference()
source.ImportFromEPSG(4326)
target = osr.SpatialReference()
target.ImportFromEPSG(3857)
transform = osr.CoordinateTransformation(source, target)
point = ogr.CreateGeometryFromWkt('POINT ({} {})'.format(float(long), float(lat)))
point.Transform(transform)
x, y = point.ExportToWkt()[7:-1].split(' ')
url = 'http://maps.six.nsw.gov.au/arcgis/rest/services/public/NSW_Property/MapServer/identify?geometry={}%2C{}&geometryType=esriGeometryPoint&sr=&layers=&layerDefs=&time=&layerTimeOptions=&tolerance=0&mapExtent=16818808.97403086%2C-4012764.233130625%2C16819095.61288684%2C-4012683.018788097&imageDisplay=600%2C550%2C96&returnGeometry=true&maxAllowableOffset=&geometryPrecision=&dynamicLayers=&returnZ=false&returnM=false&gdbVersion=&f=pjson'.format(x, y)
response = json.loads(urlopen(url).read().decode())
data = response['results'][0]['attributes']['address'].split(' ')
house_number = data.pop(0)
suburb = data.pop()
road_type = data.pop()
road_name = ' '.join(data)
url = 'http://maps.six.nsw.gov.au/services/public/Address_Location?houseNumber={}&roadName={}&roadType={}&suburb={}&postCode=2121&projection=EPSG%3A4326'.format(house_number, road_name, road_type, suburb)
response = json.loads(urlopen(url).read().decode())
new_long = response['addressResult']['addresses'][0]['addressPoint']['centreX']
new_lat = response['addressResult']['addresses'][0]['addressPoint']['centreY']
road_name = response['addressResult']['addresses'][0]['roadName']
road_type = response['addressResult']['addresses'][0]['roadType']
print('{};{};"{}";"{}"'.format(new_lat, new_long, house_number, ' '.join((road_name, road_type))))
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
"latitude";"longitude";"addr:housenumber";"addr:street"
-33.77884270754069;151.0664971864936;"51";"Dunlop Street"
-33.77888110923011;151.06632297154638;"53";"Dunlop Street"
-33.77891989637066;151.06614759128183;"55";"Dunlop Street"
-33.77883180734127;151.065975429086;"57";"Dunlop Street"
-33.77904160032425;151.06595587864607;"57A";"Dunlop Street"
-33.77899706727266;151.06579807674586;"59";"Dunlop Street"
-33.779037243830075;151.0656172822375;"61";"Dunlop Street"
-33.77871156451638;151.06570077274526;"2";"Hermington Street"
-33.778595301698516;151.06623420125453;"1";"Park Street"
-33.77846831796082;151.0669825680712;"2";"Park Street"
-33.778352261314495;151.0675096052629;"1";"Neil Street"
-33.77858282383865;151.0677655268859;"39";"Dunlop Street"
-33.77861682421399;151.0675908637397;"41";"Dunlop Street"
-33.778655754778214;151.0674163798731;"43";"Dunlop Street"
-33.77869487358601;151.0672408741128;"45";"Dunlop Street"
-33.77873401032177;151.0670654311004;"47";"Dunlop Street"
-33.77877301259783;151.06689078588215;"49";"Dunlop Street"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.