geonc 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- geonc/GeoNC.py +47 -0
- geonc/__init__.py +27 -0
- geonc/arcgis.py +173 -0
- geonc/georep.py +225 -0
- geonc-1.0.0.dist-info/METADATA +153 -0
- geonc-1.0.0.dist-info/RECORD +9 -0
- geonc-1.0.0.dist-info/WHEEL +5 -0
- geonc-1.0.0.dist-info/licenses/LICENCE +24 -0
- geonc-1.0.0.dist-info/top_level.txt +1 -0
geonc/GeoNC.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from .georep import GeorepNC
|
|
2
|
+
from .arcgis import ArcgisNC
|
|
3
|
+
from pyproj import Transformer
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class GeoNC(GeorepNC, ArcgisNC):
|
|
7
|
+
def __init__(self, max: int = 6, connect: bool = True):
|
|
8
|
+
GeorepNC.__init__(self, connect)
|
|
9
|
+
ArcgisNC.__init__(self, max, connect)
|
|
10
|
+
self._to_lambert = Transformer.from_crs(3163, 4326, always_xy=True)
|
|
11
|
+
self._to_epsg = Transformer.from_crs(4326, 3163, always_xy=True)
|
|
12
|
+
|
|
13
|
+
def to_lambert(self, x, y):
|
|
14
|
+
x1, y1 = self._to_lambert.transform(x, y)
|
|
15
|
+
return x1, y1
|
|
16
|
+
|
|
17
|
+
def to_epsg(self, x, y):
|
|
18
|
+
x1, y1 = self._to_epsg.transform(x, y)
|
|
19
|
+
return x1, y1
|
|
20
|
+
|
|
21
|
+
def get_coords_from_coords(self, x, y):
|
|
22
|
+
return self.get_from_coord(x, y)["features"][0]["geometry"]["rings"][0]
|
|
23
|
+
|
|
24
|
+
def get_coords_from_adresse(self, numero: str = "", street: str = ""):
|
|
25
|
+
val = self.get_adresse(numero, street)[0]["attributes"]
|
|
26
|
+
return self.get_from_coord(val["X"], val["Y"])["features"][0]["geometry"]["rings"][0]
|
|
27
|
+
|
|
28
|
+
def get_coords_from_batiment(self, numero: str = "", street: str = ""):
|
|
29
|
+
val = self.get_batiment(numero, street)[0]["attributes"]
|
|
30
|
+
return self.get_from_coord(val["X"], val["Y"])["features"][0]["geometry"]["rings"][0]
|
|
31
|
+
|
|
32
|
+
def get_coords_from_lieu_dit(self, numero: str = "", street: str = ""):
|
|
33
|
+
val = self.get_lieu_dit(numero, street)[0]["attributes"]
|
|
34
|
+
return self.get_from_coord(val["X"], val["Y"])["features"][0]["geometry"]["rings"][0]
|
|
35
|
+
|
|
36
|
+
def get_coords_from_maritime(self, numero: str = "", street: str = ""):
|
|
37
|
+
val = self.get_maritime(numero, street)[0]["attributes"]
|
|
38
|
+
return self.get_from_coord(val["X"], val["Y"])["features"][0]["geometry"]["rings"][0]
|
|
39
|
+
|
|
40
|
+
def get_coords_from_poi(self, numero: str = "", street: str = ""):
|
|
41
|
+
val = self.get_poi(numero, street)[0]["attributes"]
|
|
42
|
+
return self.get_from_coord(val["X"], val["Y"])["features"][0]["geometry"]["rings"][0]
|
|
43
|
+
|
|
44
|
+
def get_coords_from_nic(self, nic: str):
|
|
45
|
+
val = self.get_from_nic(nic)["content"][0]["adresses"]
|
|
46
|
+
val = self.get_adresse(val[0]["num"], val[0]["street"])[0]["attributes"]
|
|
47
|
+
return self.get_from_coord(val["X"], val["Y"])["features"][0]["geometry"]["rings"][0]
|
geonc/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from .georep import GeorepNC
|
|
2
|
+
from .arcgis import ArcgisNC
|
|
3
|
+
from .GeoNC import GeoNC
|
|
4
|
+
|
|
5
|
+
import requests, json
|
|
6
|
+
|
|
7
|
+
__title__ = 'GeoNC'
|
|
8
|
+
__author__ = 'ThePhoenix78'
|
|
9
|
+
__license__ = 'MIT'
|
|
10
|
+
__copyright__ = 'Copyright 2024-2026 ThePhoenix78'
|
|
11
|
+
__url__ = 'https://github.com/ThePhoenix78/GeoNC'
|
|
12
|
+
__newest__ = __version__ = '1.0.0'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
with requests.get("https://pypi.python.org/pypi/GeoNC/json") as response:
|
|
17
|
+
__newest__ = json.loads(response.text)["info"]["version"]
|
|
18
|
+
except Exception:
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
finally:
|
|
22
|
+
del json, requests
|
|
23
|
+
|
|
24
|
+
if __version__ < __newest__:
|
|
25
|
+
print(f"New version of {__title__} available: {__newest__} (Using {__version__})")
|
|
26
|
+
else:
|
|
27
|
+
print(f"version : {__version__}")
|
geonc/arcgis.py
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# coding : utf8
|
|
2
|
+
from urllib.parse import urlencode
|
|
3
|
+
import http.client
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ArcgisNC:
|
|
8
|
+
def __init__(self, max: int = 6, connect: bool = True):
|
|
9
|
+
self.arc_conn = None
|
|
10
|
+
self.payload = ""
|
|
11
|
+
|
|
12
|
+
self.max = max
|
|
13
|
+
|
|
14
|
+
self.headers = {
|
|
15
|
+
'cookie': "SERVERID=webadaptor2",
|
|
16
|
+
'Host': "geosgt-explocarto.gouv.nc",
|
|
17
|
+
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0",
|
|
18
|
+
'Accept': "*/*",
|
|
19
|
+
'Accept-Language': "fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3",
|
|
20
|
+
'Accept-Encoding': "json, deflate, br",
|
|
21
|
+
'Referer': "https://dtsi-sgt.maps.arcgis.com/",
|
|
22
|
+
'Origin': "https://dtsi-sgt.maps.arcgis.com",
|
|
23
|
+
'DNT': "1",
|
|
24
|
+
'Connection': "keep-alive",
|
|
25
|
+
'Sec-Fetch-Dest': "empty",
|
|
26
|
+
'Sec-Fetch-Mode': "cors",
|
|
27
|
+
'Sec-Fetch-Site': "cross-site"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
self.typical = {
|
|
31
|
+
"spatialReference": {
|
|
32
|
+
"wkid": 102100,
|
|
33
|
+
"latestWkid": 3857
|
|
34
|
+
},
|
|
35
|
+
"candidates": []
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if connect:
|
|
39
|
+
self.arc_connect()
|
|
40
|
+
|
|
41
|
+
def arc_connect(self):
|
|
42
|
+
self.arc_conn = http.client.HTTPSConnection("geosgt-explocarto.gouv.nc")
|
|
43
|
+
|
|
44
|
+
def get_all(self, numero: str = "", street: str = ""):
|
|
45
|
+
res: dict = {}
|
|
46
|
+
fin: dict = {}
|
|
47
|
+
|
|
48
|
+
res["batiment"] = self.get_batiment(numero, street)
|
|
49
|
+
res["adresse"] = self.get_adresse(numero, street)
|
|
50
|
+
res["lieu_dit"] = self.get_lieu_dit(numero, street)
|
|
51
|
+
res["maritime"] = self.get_maritime(numero, street)
|
|
52
|
+
res["poi"] = self.get_poi(numero, street)
|
|
53
|
+
|
|
54
|
+
for k, v in res.items():
|
|
55
|
+
if v != self.typical and v:
|
|
56
|
+
fin[k] = v
|
|
57
|
+
|
|
58
|
+
return fin
|
|
59
|
+
|
|
60
|
+
def get_batiment(self, numero: str = "", street: str = ""):
|
|
61
|
+
adresse = f"{numero} {street}".strip()
|
|
62
|
+
|
|
63
|
+
s = len(adresse.split())-1 if len(adresse.split()) > 1 else 0
|
|
64
|
+
|
|
65
|
+
data = {
|
|
66
|
+
"SingleLine": f"{adresse}",
|
|
67
|
+
"f": "json",
|
|
68
|
+
"outSR": {
|
|
69
|
+
"wkid": 102100,
|
|
70
|
+
"latestWkid": 3857
|
|
71
|
+
},
|
|
72
|
+
"outFields": "*",
|
|
73
|
+
"maxLocations": self.max
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
data = urlencode(data).replace("27", "22").replace("+", "%20", s).replace("%2A", "*").replace("+", "")
|
|
77
|
+
self.arc_conn.request("GET", f"/arcgis/rest/services/Geocodage/Batiment/GeocodeServer/findAddressCandidates?{data}", self.payload, self.headers)
|
|
78
|
+
|
|
79
|
+
res = self.arc_conn.getresponse()
|
|
80
|
+
fin = json.loads(res.read())
|
|
81
|
+
return fin.get("candidates", fin)
|
|
82
|
+
|
|
83
|
+
def get_adresse(self, numero: str = "", street: str = ""):
|
|
84
|
+
adresse = f"{numero} {street}".strip()
|
|
85
|
+
|
|
86
|
+
s = len(adresse.split())+1 if len(adresse.split()) > 1 else 0
|
|
87
|
+
|
|
88
|
+
data = {
|
|
89
|
+
"Single Line Input": f"{adresse}",
|
|
90
|
+
"f": "json",
|
|
91
|
+
"outSR": {
|
|
92
|
+
"wkid": 102100,
|
|
93
|
+
"latestWkid": 3857
|
|
94
|
+
},
|
|
95
|
+
"outFields": "*",
|
|
96
|
+
"maxLocations": self.max
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
data = urlencode(data).replace("27", "22").replace("+", "%20", s).replace("%2A", "*").replace("+", "")
|
|
100
|
+
self.arc_conn.request("GET", f"/arcgis/rest/services/Geocodage/Adresse/GeocodeServer/findAddressCandidates?{data}", self.payload, self.headers)
|
|
101
|
+
|
|
102
|
+
res = self.arc_conn.getresponse()
|
|
103
|
+
fin = json.loads(res.read())
|
|
104
|
+
return fin.get("candidates", fin)
|
|
105
|
+
|
|
106
|
+
def get_lieu_dit(self, numero: str = "", street: str = ""):
|
|
107
|
+
adresse = f"{numero} {street}".strip()
|
|
108
|
+
|
|
109
|
+
s = len(adresse.split())-1 if len(adresse.split()) > 1 else 0
|
|
110
|
+
|
|
111
|
+
data = {
|
|
112
|
+
"SingleLine": f"{adresse}",
|
|
113
|
+
"f": "json",
|
|
114
|
+
"outSR": {
|
|
115
|
+
"wkid": 102100,
|
|
116
|
+
"latestWkid": 3857
|
|
117
|
+
},
|
|
118
|
+
"outFields": "*",
|
|
119
|
+
"maxLocations": self.max
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
data = urlencode(data).replace("27", "22").replace("+", "%20", s).replace("%2A", "*").replace("+", "")
|
|
123
|
+
self.arc_conn.request("GET", f"/arcgis/rest/services/Geocodage/Lieu_dit/GeocodeServer/findAddressCandidates?{data}", self.payload, self.headers)
|
|
124
|
+
|
|
125
|
+
res = self.arc_conn.getresponse()
|
|
126
|
+
fin = json.loads(res.read())
|
|
127
|
+
return fin.get("candidates", fin)
|
|
128
|
+
|
|
129
|
+
def get_maritime(self, numero: str = "", street: str = ""):
|
|
130
|
+
adresse = f"{numero} {street}".strip()
|
|
131
|
+
|
|
132
|
+
s = len(adresse.split())-1 if len(adresse.split()) > 1 else 0
|
|
133
|
+
|
|
134
|
+
data = {
|
|
135
|
+
"SingleLine": f"{adresse}",
|
|
136
|
+
"f": "json",
|
|
137
|
+
"outSR": {
|
|
138
|
+
"wkid": 102100,
|
|
139
|
+
"latestWkid": 3857
|
|
140
|
+
},
|
|
141
|
+
"outFields": "*",
|
|
142
|
+
"maxLocations": self.max
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
data = urlencode(data).replace("27", "22").replace("+", "%20", s).replace("%2A", "*").replace("+", "")
|
|
146
|
+
self.arc_conn.request("GET", f"/arcgis/rest/services/Geocodage/maritime/GeocodeServer/findAddressCandidates?{data}", self.payload, self.headers)
|
|
147
|
+
|
|
148
|
+
res = self.arc_conn.getresponse()
|
|
149
|
+
fin = json.loads(res.read())
|
|
150
|
+
return fin.get("candidates", fin)
|
|
151
|
+
|
|
152
|
+
def get_poi(self, numero: str = "", street: str = ""):
|
|
153
|
+
adresse = f"{numero} {street}".strip()
|
|
154
|
+
|
|
155
|
+
s = len(adresse.split())-1 if len(adresse.split()) > 1 else 0
|
|
156
|
+
|
|
157
|
+
data = {
|
|
158
|
+
"SingleLine": f"{adresse}",
|
|
159
|
+
"f": "json",
|
|
160
|
+
"outSR": {
|
|
161
|
+
"wkid": 102100,
|
|
162
|
+
"latestWkid": 3857
|
|
163
|
+
},
|
|
164
|
+
"outFields": "*",
|
|
165
|
+
"maxLocations": self.max
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
data = urlencode(data).replace("27", "22").replace("+", "%20", s).replace("%2A", "*").replace("+", "")
|
|
169
|
+
self.arc_conn.request("GET", f"/arcgis/rest/services/Geocodage/Poi/GeocodeServer/findAddressCandidates?{data}", self.payload, self.headers)
|
|
170
|
+
|
|
171
|
+
res = self.arc_conn.getresponse()
|
|
172
|
+
fin = json.loads(res.read())
|
|
173
|
+
return fin.get("candidates", fin)
|
geonc/georep.py
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# coding : utf8
|
|
2
|
+
from urllib.parse import urlencode
|
|
3
|
+
import http.client
|
|
4
|
+
import json
|
|
5
|
+
import gzip
|
|
6
|
+
|
|
7
|
+
# Fonds DITTT - Gouvernement de la Nouvelle-Calédonie (2021)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class GeorepNC:
|
|
11
|
+
def __init__(self, connect: bool = True):
|
|
12
|
+
self.geo_conn = None
|
|
13
|
+
self.tile_conn = None
|
|
14
|
+
self.payload = ""
|
|
15
|
+
|
|
16
|
+
self.image_request = "https://geosgt.gouv.nc/public/rest/services/fond_imagerie/MapServer/tile"
|
|
17
|
+
|
|
18
|
+
self.request_header = {
|
|
19
|
+
'Host': "cadastre.gouv.nc",
|
|
20
|
+
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0",
|
|
21
|
+
'Accept': "application/json, text/plain, */*",
|
|
22
|
+
'Accept-Language': "fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3",
|
|
23
|
+
'Accept-Encoding': "json",
|
|
24
|
+
'Referer': "https://cadastre.gouv.nc/",
|
|
25
|
+
'DNT': "1",
|
|
26
|
+
'Connection': "keep-alive",
|
|
27
|
+
'Cookie': "SERVERID=webadaptor1",
|
|
28
|
+
'Sec-Fetch-Dest': "empty",
|
|
29
|
+
'Sec-Fetch-Mode': "cors",
|
|
30
|
+
'Sec-Fetch-Site': "same-origin"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
self.coord_headers = {
|
|
34
|
+
'Host': "cadastre.gouv.nc",
|
|
35
|
+
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0",
|
|
36
|
+
'Accept': "*/*",
|
|
37
|
+
'Accept-Language': "fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3",
|
|
38
|
+
'Accept-Encoding': "json, deflate, br",
|
|
39
|
+
'Referer': "https://cadastre.gouv.nc/",
|
|
40
|
+
'DNT': "1",
|
|
41
|
+
'Connection': "keep-alive",
|
|
42
|
+
'Cookie': "SERVERID=webadaptor1",
|
|
43
|
+
'Sec-Fetch-Dest': "empty",
|
|
44
|
+
'Sec-Fetch-Mode': "cors",
|
|
45
|
+
'Sec-Fetch-Site': "same-origin"
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
self.nic_header = {
|
|
49
|
+
'Host': "cadastre.gouv.nc",
|
|
50
|
+
'Connection': "keep-alive",
|
|
51
|
+
'sec-ch-ua': 'Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
|
|
52
|
+
'Accept': "application/json, text/plain, */*",
|
|
53
|
+
'sec-ch-ua-mobile': "?0",
|
|
54
|
+
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.8 Safari/537.36",
|
|
55
|
+
'sec-ch-ua-platform': "Windows",
|
|
56
|
+
'Sec-Fetch-Site': "same-origin",
|
|
57
|
+
'Sec-Fetch-Mode': "cors",
|
|
58
|
+
'Sec-Fetch-Dest': "empty",
|
|
59
|
+
'Referer': "https://cadastre.gouv.nc/",
|
|
60
|
+
'Accept-Encoding': "gzip, deflate, br",
|
|
61
|
+
'Accept-Language': "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7",
|
|
62
|
+
'Cookie': "SERVERID=webadaptor2",
|
|
63
|
+
'dnt': "1"
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if connect:
|
|
67
|
+
self.geo_connect()
|
|
68
|
+
self.tile_connect()
|
|
69
|
+
|
|
70
|
+
def geo_connect(self):
|
|
71
|
+
"""
|
|
72
|
+
connect to the cadastre socket
|
|
73
|
+
"""
|
|
74
|
+
self.geo_conn = http.client.HTTPSConnection("cadastre.gouv.nc")
|
|
75
|
+
|
|
76
|
+
def tile_connect(self):
|
|
77
|
+
"""
|
|
78
|
+
connect to the tile socket (png)
|
|
79
|
+
"""
|
|
80
|
+
self.tile_conn = http.client.HTTPSConnection("geosgt.gouv.nc")
|
|
81
|
+
|
|
82
|
+
def get_tile(self, zoom: int = 0, y: int = 0, x: int = 0, out_border: bool = False, check_out_border: bool = True):
|
|
83
|
+
"""
|
|
84
|
+
parameters :
|
|
85
|
+
zoom (int) : the zoom (3-13),
|
|
86
|
+
y (int) : the y coord (epsg 3163),
|
|
87
|
+
x (int) : the x coord (epsg 3163),
|
|
88
|
+
outborder (bool) : get the map out of the nc
|
|
89
|
+
check_outborder (bool) : return False if out of th map, else a blue square
|
|
90
|
+
return a tile (png/jpeg)
|
|
91
|
+
"""
|
|
92
|
+
blank = "true" if out_border else "false"
|
|
93
|
+
link = f"{self.image_request}/{zoom}/{y}/{x}?blankTile={blank}"
|
|
94
|
+
headers = {'cookie': "SERVERID=webadaptor2"}
|
|
95
|
+
|
|
96
|
+
self.tile_conn.request("GET", link, headers=headers)
|
|
97
|
+
res = self.tile_conn.getresponse()
|
|
98
|
+
data = res.read()
|
|
99
|
+
|
|
100
|
+
if not check_out_border and len(data) <= 775:
|
|
101
|
+
return False
|
|
102
|
+
|
|
103
|
+
return data
|
|
104
|
+
|
|
105
|
+
def get_info(self, adresse: str = ""):
|
|
106
|
+
"""
|
|
107
|
+
return the informations related to the adresse
|
|
108
|
+
"""
|
|
109
|
+
data = {
|
|
110
|
+
"filter": {
|
|
111
|
+
"searchText": f"{adresse}",
|
|
112
|
+
"stateIds": [1]
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
data = urlencode(data).replace("27", "22").replace("+", "%20").replace("%20", "", 1)
|
|
116
|
+
self.geo_conn.request("GET", f"/api/parcel/fts?{data}", self.payload, self.request_header)
|
|
117
|
+
res = self.geo_conn.getresponse()
|
|
118
|
+
fin = res.read()
|
|
119
|
+
return json.loads(fin)
|
|
120
|
+
|
|
121
|
+
def get_adresse_list(self, numero: str = "", street: str = "", nic: str = ""):
|
|
122
|
+
"""
|
|
123
|
+
parameters :
|
|
124
|
+
numero (int or str) : the numero of the adresse,
|
|
125
|
+
street (str) : the street of the adresse
|
|
126
|
+
return a list of dict associated with the adresse's information
|
|
127
|
+
id : the id of the adresse
|
|
128
|
+
num : the numero of the adresse
|
|
129
|
+
street : the street's name
|
|
130
|
+
nic : the nic (Numero d Inventaire Cadastral)
|
|
131
|
+
"""
|
|
132
|
+
numero = str(numero)
|
|
133
|
+
adresse = f"{numero} {street}".strip()
|
|
134
|
+
if nic:
|
|
135
|
+
adresse = nic.strip()
|
|
136
|
+
dico = self.get_info(adresse)
|
|
137
|
+
adr = street.lower().strip().split()
|
|
138
|
+
|
|
139
|
+
if nic:
|
|
140
|
+
return dico["content"]
|
|
141
|
+
|
|
142
|
+
for values in dico["content"]:
|
|
143
|
+
try:
|
|
144
|
+
if adresse.lower() == values["ftsAddressLabel"].lower():
|
|
145
|
+
return values["adresses"]
|
|
146
|
+
for val in values["adresses"]:
|
|
147
|
+
if numero == val["num"] and [True for i in adr if i in val["street"].lower()]:
|
|
148
|
+
return values["adresses"]
|
|
149
|
+
except Exception:
|
|
150
|
+
pass
|
|
151
|
+
|
|
152
|
+
def get_from_adresse(self, numero: str = "", street: str = "", nic: str = ""):
|
|
153
|
+
"""
|
|
154
|
+
parameters :
|
|
155
|
+
numero (str) : the numero of the adresse,
|
|
156
|
+
street (str) : the street of the adresse
|
|
157
|
+
return a list of dict associated with the adresse's information
|
|
158
|
+
"""
|
|
159
|
+
numero = str(numero)
|
|
160
|
+
adresse = f"{numero} {street}".strip()
|
|
161
|
+
|
|
162
|
+
if nic:
|
|
163
|
+
adresse = nic.strip()
|
|
164
|
+
|
|
165
|
+
dico = self.get_info(adresse)
|
|
166
|
+
adr = street.lower().strip().split()
|
|
167
|
+
|
|
168
|
+
if nic:
|
|
169
|
+
return dico["content"]
|
|
170
|
+
|
|
171
|
+
for values in dico["content"]:
|
|
172
|
+
try:
|
|
173
|
+
if adresse.lower() == values["ftsAddressLabel"].lower():
|
|
174
|
+
return values
|
|
175
|
+
for val in values["adresses"]:
|
|
176
|
+
if numero == val["num"] and [True for i in adr if i in val["street"].lower()]:
|
|
177
|
+
return values
|
|
178
|
+
except Exception:
|
|
179
|
+
pass
|
|
180
|
+
|
|
181
|
+
def get_from_nic(self, nic: str):
|
|
182
|
+
"""
|
|
183
|
+
parameters :
|
|
184
|
+
nic : the nic (Numero d Inventaire Cadastral)
|
|
185
|
+
return a list of dict associated with the adresse's information
|
|
186
|
+
"""
|
|
187
|
+
data = {
|
|
188
|
+
"filter": {
|
|
189
|
+
"ref": f"{nic}"
|
|
190
|
+
},
|
|
191
|
+
"size": 1,
|
|
192
|
+
"page": 0
|
|
193
|
+
}
|
|
194
|
+
data = urlencode(data).replace("27", "22").replace("+", "%20").replace("%20", "", 1)
|
|
195
|
+
self.geo_conn.request("GET", f"/api/parcel?{data}", self.payload, self.nic_header)
|
|
196
|
+
res = self.geo_conn.getresponse()
|
|
197
|
+
return json.loads(gzip.decompress(res.read()).decode())
|
|
198
|
+
|
|
199
|
+
def get_from_coord(self, x, y):
|
|
200
|
+
data = {
|
|
201
|
+
"f": "json",
|
|
202
|
+
"distance": "150000000000",
|
|
203
|
+
"geometry": {
|
|
204
|
+
"spatialReference": {
|
|
205
|
+
"latestWkid": "3163",
|
|
206
|
+
"wkid": "3163"
|
|
207
|
+
},
|
|
208
|
+
"x": f"{x}",
|
|
209
|
+
"y": f"{y}"
|
|
210
|
+
},
|
|
211
|
+
"outFields": "*",
|
|
212
|
+
"outSR": "3163",
|
|
213
|
+
"spatialRel": "esriSpatialRelIntersects",
|
|
214
|
+
"where": "1=1",
|
|
215
|
+
"geometryType": "esriGeometryPoint",
|
|
216
|
+
"inSR": "316"
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
data = urlencode(data).replace("27", "22").replace("+", "%20").replace("%20", "", 1)
|
|
220
|
+
self.geo_conn.request("GET", f"/arcgisServices/cadastreV3/cadastre_consult_v3/MapServer/7/query?{data}", self.payload, self.coord_headers)
|
|
221
|
+
res = self.geo_conn.getresponse()
|
|
222
|
+
res = res.read()
|
|
223
|
+
res = json.loads(res)
|
|
224
|
+
# return res
|
|
225
|
+
return {"geometryType": res["geometryType"], "spatialReference": res["spatialReference"], "features": res["features"]}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: geonc
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: API de geolocalisation pour la Nouvelle-Calédonie
|
|
5
|
+
Home-page: https://github.com/ThePhoenix78/GeoNC
|
|
6
|
+
Download-URL: https://github.com/ThePhoenix78/GeoNC/tarball/master
|
|
7
|
+
Author: ThePhoenix78
|
|
8
|
+
Author-email: thephoenix788@gmail.com
|
|
9
|
+
License: MIT
|
|
10
|
+
Keywords: georep,arcgis,SIG,cadastre,nouvelle-caledonie
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENCE
|
|
16
|
+
Requires-Dist: requests
|
|
17
|
+
Requires-Dist: aiohttp
|
|
18
|
+
Dynamic: author
|
|
19
|
+
Dynamic: author-email
|
|
20
|
+
Dynamic: classifier
|
|
21
|
+
Dynamic: description
|
|
22
|
+
Dynamic: description-content-type
|
|
23
|
+
Dynamic: download-url
|
|
24
|
+
Dynamic: home-page
|
|
25
|
+
Dynamic: keywords
|
|
26
|
+
Dynamic: license
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
Dynamic: requires-dist
|
|
29
|
+
Dynamic: summary
|
|
30
|
+
|
|
31
|
+
# GeoNC
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### utilisation de l'API
|
|
35
|
+
|
|
36
|
+
* ##### GeorepNC
|
|
37
|
+
|
|
38
|
+
* ##### ArcgisNC
|
|
39
|
+
|
|
40
|
+
* ##### GeoNC
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## GeorepNC
|
|
44
|
+
|
|
45
|
+
### Arguments
|
|
46
|
+
|
|
47
|
+
* __connect__ : bool = True
|
|
48
|
+
|
|
49
|
+
### Paramètres
|
|
50
|
+
|
|
51
|
+
* __geo_conn__ : la connection avec le serveur
|
|
52
|
+
* __payload__ : infos pour les requetes (ne pas toucher)
|
|
53
|
+
* __request_header__ : header des requetes liées aux demandes vers le serveur
|
|
54
|
+
* __coord_headers__ : header des requetes liées aux coordonées
|
|
55
|
+
* __nic_header__ : header des requetes liées au NIC
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
### Méthodes
|
|
59
|
+
* __geo_connect__ : permet de lier le client au serveur (automatique)
|
|
60
|
+
|
|
61
|
+
* __get_info__ _(adresse : str)_ : permet de retourner des infos liées a l'adresse
|
|
62
|
+
|
|
63
|
+
* __get_adresse_list__ _(numero: str="", street: str="", nic: str="")_ : permet de retourner une liste d'adresse correspondant a la requete
|
|
64
|
+
|
|
65
|
+
* __get_from_adresse__ _(numero: str="", street: str="", nic="")_ : retourne les informations complètes liées a l'adresse / nic
|
|
66
|
+
|
|
67
|
+
* __get_from_nic__ _(nic: str)_ : retourne les informations relative au nic
|
|
68
|
+
|
|
69
|
+
* __get_from_coord__ _(x, y)_ : retourne les informations correspondant aux coordonnées
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
## ArcgisNC
|
|
73
|
+
|
|
74
|
+
### Arguments
|
|
75
|
+
|
|
76
|
+
* __max__ : int = 6 , le nombre maximum d'éléments dans la réponse
|
|
77
|
+
* __connect__ : bool = True
|
|
78
|
+
|
|
79
|
+
### Paramètres
|
|
80
|
+
|
|
81
|
+
* __arc_conn__ : la connection avec le serveur
|
|
82
|
+
* __payload__ : infos pour les requetes (ne pas toucher)
|
|
83
|
+
* __headers__ : header des requetes liées aux demandes vers le serveur
|
|
84
|
+
* __typical__ : données comprise dans les réponses vides
|
|
85
|
+
|
|
86
|
+
### Méthodes
|
|
87
|
+
* __arc_connect__ : permet de lier le client au serveur (automatique)
|
|
88
|
+
|
|
89
|
+
* __get_batiment__ _(numero: str="", street: str="")_ : permet de retourner une liste de batiments correspondant a la requete
|
|
90
|
+
|
|
91
|
+
* __get_lieu_dit__ _(numero: str="", street: str="")_ : permet de retourner une liste de lieux dit correspondant a la requete
|
|
92
|
+
|
|
93
|
+
* __get_adresse__ _(numero: str="", street: str="")_ : permet de retourner une liste d'adresses correspondant a la requete
|
|
94
|
+
|
|
95
|
+
* __get_maritime__ _(numero: str="", street: str="")_ : permet de retourner une liste d'espaces maritime correspondant a la requete
|
|
96
|
+
|
|
97
|
+
* __get_poi__ _(numero: str="", street: str="")_ : permet de retourner une liste de POI correspondant a la requete
|
|
98
|
+
|
|
99
|
+
* __get_all__ _(numero: str = "", street: str = "")_ : retourne le résultat (si il existe) de toute les requetes au dessus
|
|
100
|
+
|
|
101
|
+
## GeoNC
|
|
102
|
+
|
|
103
|
+
### Une combinaison de GeorepNC et ArcgisNC
|
|
104
|
+
|
|
105
|
+
### Arguments
|
|
106
|
+
|
|
107
|
+
* __max__ : int = 6 , le nombre maximum d'éléments dans la réponse
|
|
108
|
+
* __connect__ : bool = True
|
|
109
|
+
|
|
110
|
+
### Paramètres
|
|
111
|
+
|
|
112
|
+
* __\_to_lambert__ : classe pour transformer du espg (nc) en lambert (universel) (ne pas toucher)
|
|
113
|
+
* __\_to_epsg__ : classe pour transformer du lambert (universel) en espg (nc) (ne pas toucher)
|
|
114
|
+
|
|
115
|
+
### Méthodes
|
|
116
|
+
* __to_lambert__ _(x: int, y: int)_ : transforme des coords de espg en lambert, retourne un x y
|
|
117
|
+
|
|
118
|
+
* __to_epsg__ _(x: int, y: int)_ : transforme des coords de lambert en epsg, retourne un x y
|
|
119
|
+
|
|
120
|
+
* __get_coords_from_adresse__ _(numero: str="", street: str="")_ : permet de retourner une liste de coordonnées correspondant a l'adresse
|
|
121
|
+
|
|
122
|
+
* __get_coords_from_batiment__ _(numero: str="", street: str="")_ : permet de retourner une liste de coordonnées correspondant au batiment
|
|
123
|
+
|
|
124
|
+
* __get_coords_from_lieu_dit__ _(numero: str="", street: str="")_ : permet de retourner une liste de coordonnées correspondant au lieux dit
|
|
125
|
+
|
|
126
|
+
* __get_coords_from_maritime__ _(numero: str="", street: str="")_ : permet de retourner une liste de coordonnées correspondant a l'espace maritime
|
|
127
|
+
|
|
128
|
+
* __get_coords_from_poi__ _(numero: str="", street: str="")_ : permet de retourner une liste de coordonnées correspondant au poi
|
|
129
|
+
|
|
130
|
+
* __get_coords_from_nic__ _(nic: str)_ : permet de retourner une liste de coordonnées correspondant au nic
|
|
131
|
+
|
|
132
|
+
* __get_coords_from_coords__ _(x, y)_ : permet de retourner une liste de coordonnées correspondant au coordonées entrées
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
### Exemple de code
|
|
136
|
+
```py
|
|
137
|
+
from geonc import GeoNC
|
|
138
|
+
|
|
139
|
+
client = GeoNC()
|
|
140
|
+
|
|
141
|
+
val1 = client.get_maritime(street="Nouméa")
|
|
142
|
+
val2 = client.get_from_nic("xxxxx-xxxx")
|
|
143
|
+
val3 = client.get_from_coord(10, 20)
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Mention légales georep : https://cadastre.gouv.nc/a-propos
|
|
148
|
+
|
|
149
|
+
Mention légales arcgis : https://georep-dtsi-sgt.opendata.arcgis.com/pages/conditions-generales-dutilisation
|
|
150
|
+
|
|
151
|
+
_API faite a but éducative (dans le cadre de l'interopérabilité avec le langage python)_
|
|
152
|
+
|
|
153
|
+
_je ne suis pas responsable de ce que vous en faite_
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
geonc/GeoNC.py,sha256=boz7iKRsrbPhAMhDGqQNl95c6K9SldedZ8BiwVzJFTE,2248
|
|
2
|
+
geonc/__init__.py,sha256=CI3uyF2QtJJiSIBVfDYVFN3gRecTnyyffsyWBU9_TAc,708
|
|
3
|
+
geonc/arcgis.py,sha256=wULCVdDXlKKgwSoxikK7yVGJ-AMPvXyKVNB3pIl-6kk,6356
|
|
4
|
+
geonc/georep.py,sha256=_YIcwf1bUQVxOuU67mA4as5x71yBxnW1QGT4V8F9Nzw,8626
|
|
5
|
+
geonc-1.0.0.dist-info/licenses/LICENCE,sha256=6qToijrICJohpSsSdWKjSVNQ89lzDiGs4OrR98ifjOQ,1243
|
|
6
|
+
geonc-1.0.0.dist-info/METADATA,sha256=EDCqLdr4efC-bVMWaDyK_z_z8-HrLxE3Q7XTkHcBklM,5422
|
|
7
|
+
geonc-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
+
geonc-1.0.0.dist-info/top_level.txt,sha256=OkqhO_DeFbTRIf8iSY12JzztOmhcy4SIbwCBpGGUtxU,6
|
|
9
|
+
geonc-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Copyright (c) 2021
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
https://cadastre.gouv.nc/a-propos
|
|
15
|
+
https://georep-dtsi-sgt.opendata.arcgis.com/pages/conditions-generales-dutilisation
|
|
16
|
+
I am not responsible for your use of the software / code
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
21
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
22
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
23
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
24
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
geonc
|