ESCatastroLib 0.0.1rc0__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.
@@ -0,0 +1,3 @@
1
+ # ESCatastroLib/__init__.py
2
+ from .models import Calle, Municipio, ParcelaCatastral, MetaParcela
3
+ from .utils import exceptions, statics, utils
@@ -0,0 +1,49 @@
1
+ from .Municipio import Municipio
2
+ from ..utils.statics import URL_BASE_CALLEJERO
3
+ from ..utils.utils import comprobar_errores
4
+
5
+ import requests
6
+ import json
7
+
8
+ class Calle:
9
+ """
10
+ Clase que representa una calle.
11
+ Args:
12
+ municipio (Municipio): Objeto que representa el municipio al que pertenece la calle.
13
+ nombre_calle (str, optional): Nombre de la calle. Default es None.
14
+ tipo_via (str, optional): Tipo de vía de la calle. Default es None.
15
+ Raises:
16
+ Exception: Se produce cuando ocurre un error al asignar la calle.
17
+ Exception: Se produce cuando no se especifica el nombre de la calle.
18
+ Exception: Se produce cuando no se encuentran calles disponibles.
19
+ Attributes:
20
+ calle (str): Nombre de la calle asignada.
21
+ tipo_via (str): Tipo de vía de la calle asignada.
22
+ municipio (Municipio): Objeto que representa el municipio al que pertenece la calle.
23
+ """
24
+
25
+ def __init__(self, municipio: Municipio, nombre_calle: str|None = None, tipo_via: str|None = None):
26
+ uri = f'{URL_BASE_CALLEJERO}/ObtenerCallejero'
27
+
28
+ request = requests.get(uri, params={
29
+ 'Provincia': municipio.provincia,
30
+ 'Municipio': municipio.municipio,
31
+ 'NomVia': nombre_calle,
32
+ 'TipoVia': tipo_via
33
+ })
34
+
35
+ if request.status_code == 200:
36
+ calle_dict = json.loads(request.text)
37
+
38
+ if comprobar_errores(calle_dict) and nombre_calle:
39
+ if len(calle_dict.get('consulta_callejeroResult').get('callejero').get('calle')) == 1:
40
+ self.calle = calle_dict.get('consulta_callejeroResult').get('callejero').get('calle')[0].get('dir').get('nv')
41
+ self.tipo_via = calle_dict.get('consulta_callejeroResult').get('callejero').get('calle')[0].get('dir').get('tv')
42
+ self.municipio = municipio
43
+ else:
44
+ raise Exception(f"""Error al asignar calle. No has especificado la calle completamente, o ese nombre está en varios lados (indica el tipo de vía que aparezca al principio de la vía como PZ o CL). Estas son las calles disponibles con esa búsqueda: {','.join(f"{cl.get('dir').get('tv')} {cl.get('dir').get('nv')}" for cl in calle_dict.get('consulta_callejeroResult').get('callejero').get('calle'))}""")
45
+ else:
46
+ raise Exception(f"""Error al asignar calle. No has especificado la calle. Estas son las calles disponibles: {','.join(f"{cl.get('dir').get('tv')} {cl.get('dir').get('nv')}" for cl in calle_dict.get('consulta_callejeroResult').get('callejero').get('calle'))}""")
47
+
48
+ else:
49
+ raise Exception(f'Error al listar calles: Puede que no exista ese municipio.')
@@ -0,0 +1,303 @@
1
+ import requests
2
+ import json
3
+ import xmltodict
4
+
5
+ from ..utils.statics import URL_BASE_CALLEJERO, URL_BASE_GEOGRAFIA, URL_BASE_CROQUIS_DATOS
6
+ from ..utils.utils import comprobar_errores
7
+ from ..utils.exceptions import ErrorServidorCatastro
8
+ from .Calle import Calle, Municipio
9
+
10
+ class ParcelaCatastral:
11
+ """
12
+ Clase que representa una parcela catastral.
13
+ Args:
14
+ rc (str, optional): La referencia catastral de la parcela. Defaults to None. Puede ir solo.
15
+
16
+ provincia (int|str, optional): El código o nombre de la provincia. Defaults to None. Se usa para buscar por dirección o parcela.
17
+ municipio (int|str, optional): El código o nombre del municipio. Defaults to None. Se usa para buscar por dirección o parcela.
18
+ poligono (int, optional): El número del polígono. Defaults to None. Se usa para buscar por parcela.
19
+ parcela (int, optional): El número de la parcela. Defaults to None. Se usa para buscar por parcela.
20
+ tipo_via (str, optional): El tipo de vía de la dirección. Defaults to None. Se usa para buscar por dirección.
21
+ calle (str, optional): El nombre de la calle de la dirección. Defaults to None. Se usa para buscar por dirección.
22
+ numero (str, optional): El número de la dirección. Defaults to None. Se usa para buscar por dirección.
23
+ Raises:
24
+ ValueError: Se lanza si no se proporciona suficiente información para realizar la búsqueda o si la RC corresponde a una MetaParcela.
25
+ ErrorServidorCatastro: Se lanza si hay un error en el servidor del Catastro.
26
+ Attributes:
27
+ rc (str): La referencia catastral de la parcela.
28
+ provincia (int|str): El código o nombre de la provincia.
29
+ municipio (int|str): El código o nombre del municipio.
30
+ poligono (int): El número del polígono. Sólo se da en terrenos Rústicos.
31
+ parcela (int): El número de la parcela. Sólo se da en terrenos Rústicos.
32
+ tipo_via (str): El tipo de vía de la dirección. Sólo se da en terrenos Urbanos.
33
+ calle (str): El nombre de la calle de la dirección. Sólo se da en terrenos Urbanos.
34
+ numero (str): El número de la dirección. Sólo se da en terrenos Urbanos.
35
+ url_croquis (str): La URL del croquis de la parcela.
36
+ tipo (str): El tipo de la parcela (Urbano o Rústico).
37
+ antiguedad (str): La antigüedad de la parcela (solo para parcelas urbanas).
38
+ uso (str): El uso de la parcela (solo para parcelas urbanas).
39
+ nombre_paraje (str): El nombre del paraje (solo para parcelas rústicas).
40
+ regiones (list): Una lista de regiones de la parcela, cada una con una descripción y superficie.
41
+ geocentro (dict): Las coordenadas del geocentro de la parcela.
42
+ geometria (list): Una lista de puntos que representan la geometría de la parcela.
43
+ """
44
+
45
+ def __create_regions(self, info_cadastre: dict):
46
+ self.regiones = []
47
+ if self.tipo == 'Urbano':
48
+ iterator = list(info_cadastre.values())[0].get('bico').get('lcons')
49
+ elif self.tipo == 'Rústico':
50
+ iterator = list(info_cadastre.values())[0].get('bico').get('lspr')
51
+ for region in iterator:
52
+ if self.tipo == 'Rústico':
53
+ self.regiones.append({
54
+ 'descripcion': region.get('dspr').get('dcc'),
55
+ 'superficie': region.get('dspr').get('ssp')
56
+ })
57
+ elif self.tipo == 'Urbano':
58
+ self.regiones.append({
59
+ 'descripcion': region.get('lcd'),
60
+ 'superficie': region.get('dfcons').get('stl')
61
+ })
62
+
63
+
64
+ def __create_geometry(self):
65
+ geometry_request = requests.get(f'{URL_BASE_GEOGRAFIA}',
66
+ params={
67
+ 'service':'wfs',
68
+ 'version':'2',
69
+ 'request':'getfeature',
70
+ 'STOREDQUERIE_ID':'GetParcel',
71
+ 'refcat': self.rc,
72
+ 'srsname': 'EPSG:4326'
73
+ })
74
+
75
+ geometry = xmltodict.parse(geometry_request.content)
76
+ geoposition = geometry.get('FeatureCollection').get('member').get('cp:CadastralParcel').get('cp:referencePoint').get('gml:Point').get('gml:pos').split(' ')
77
+ self.geocentro = {
78
+ 'x': geoposition[0],
79
+ 'y': geoposition[1]
80
+ }
81
+ parcel_geometry = geometry.get('FeatureCollection').get('member').get('cp:CadastralParcel').get('cp:geometry').get('gml:MultiSurface').get('gml:surfaceMember').get('gml:Surface').get('gml:patches').get('gml:PolygonPatch').get('gml:exterior').get('gml:LinearRing').get('gml:posList').get('#text').split(' ')
82
+ self.geometria = [
83
+ {
84
+ 'x': parcel_geometry[2*idx],
85
+ 'y': parcel_geometry[2*idx+1]
86
+ } for idx in range(len(parcel_geometry)//2)
87
+ ]
88
+
89
+ def __create_from_rc(self, rc: str):
90
+ """Create an instance of InfoCatastral from a RC (Referencia Catastral) string."""
91
+ req1 = requests.get(f'{URL_BASE_CALLEJERO}/Consulta_DNPRC',
92
+ params={'RefCat': rc})
93
+
94
+ info_cadastre = json.loads(req1.content)
95
+ if comprobar_errores(info_cadastre):
96
+ cudnp = info_cadastre.get("consulta_dnprcResult", {}).get("control", {}).get("cudnp", 1)
97
+
98
+ if cudnp > 1:
99
+ raise ErrorServidorCatastro(mensaje="Esta parcela tiene varias referencias catastrales. Usa un objeto MetaParcela.")
100
+ else:
101
+ self.url_croquis = requests.get(URL_BASE_CROQUIS_DATOS, params={'refcat': self.rc}).url
102
+ self.municipio = info_cadastre.get('consulta_dnprcResult').get('bico').get('bi').get('dt').get('nm')
103
+ self.provincia = info_cadastre.get('consulta_dnprcResult').get('bico').get('bi').get('dt').get('np')
104
+ self.tipo = 'Rústico' if info_cadastre.get('consulta_dnprcResult').get('bico').get('bi').get('idbi').get('cn') == 'RU' else 'Urbano'
105
+ if self.tipo == 'Urbano':
106
+ self.calle = f"{info_cadastre.get('consulta_dnprcResult').get('bico').get('bi').get('dt').get('locs').get('lous').get('lourb').get('dir').get('tv')} {info_cadastre.get('consulta_dnprcResult').get('bico').get('bi').get('dt').get('locs').get('lous').get('lourb').get('dir').get('nv')}"
107
+ self.numero = info_cadastre.get('consulta_dnprcResult').get('bico').get('bi').get('dt').get('locs').get('lous').get('lourb').get('dir').get('pnp')
108
+ self.antiguedad = info_cadastre.get('consulta_dnprcResult').get('bico').get('bi').get('debi').get('ant')
109
+ self.uso = info_cadastre.get('consulta_dnprcResult').get('bico').get('bi').get('debi').get('luso')
110
+ elif self.tipo == 'Rústico':
111
+ self.parcela = info_cadastre.get('consulta_dnprcResult').get('bico').get('bi').get('dt').get('locs').get('lors').get('lorus').get('cpp').get('cpa')
112
+ self.poligono = info_cadastre.get('consulta_dnprcResult').get('bico').get('bi').get('dt').get('locs').get('lors').get('lorus').get('cpp').get('cpo')
113
+ self.nombre_paraje = info_cadastre.get('consulta_dnprcResult').get('bico').get('bi').get('dt').get('locs').get('lors').get('lorus').get('npa')
114
+
115
+ self.__create_regions(info_cadastre)
116
+ self.__create_geometry()
117
+
118
+ self.superficie = sum(float(region.get('superficie')) for region in self.regiones)
119
+
120
+ def __create_from_parcel(self, provincia: str|None, municipio: str|None, poligono: str|None, parcela: str|None):
121
+ """Create an instance of InfoCatastral from a parcela string."""
122
+ req = requests.get(f'{URL_BASE_CALLEJERO}/Consulta_DNPPP',
123
+ params={
124
+ 'Provincia': provincia,
125
+ 'Municipio': municipio,
126
+ 'Poligono': poligono,
127
+ 'Parcela': parcela
128
+ })
129
+
130
+ info_cadastre = json.loads(req.content)
131
+ if comprobar_errores(info_cadastre):
132
+ cudnp = info_cadastre.get("consulta_dnpppResult", {}).get("control", {}).get("cudnp", 1)
133
+
134
+ if cudnp > 1:
135
+ raise ErrorServidorCatastro(mensaje="Esta parcela tiene varias referencias catastrales. Usa un objeto MetaParcela.")
136
+ else:
137
+ self.rc = ''.join(info_cadastre.get('consulta_dnpppResult').get('bico').get('bi').get('idbi').get('rc').values())
138
+ self.__create_from_rc(self.rc)
139
+
140
+ def __create_from_address(self, provincia: str|None, municipio: str|None, tipo_via: str|None, calle: str|None, numero: str|None):
141
+ """Create an instance of InfoCatastral from an address string."""
142
+ info_calle = Calle(
143
+ municipio=Municipio(
144
+ provincia=provincia,
145
+ municipio=municipio
146
+ ),
147
+ tipo_via=tipo_via,
148
+ nombre_calle=calle
149
+ )
150
+
151
+ if info_calle:
152
+ req = requests.get(f'{URL_BASE_CALLEJERO}/Consulta_DNPLOC',
153
+ params={
154
+ 'Provincia': info_calle.municipio.provincia,
155
+ 'Municipio': info_calle.municipio.municipio,
156
+ 'Sigla': info_calle.tipo_via,
157
+ 'Calle': info_calle.calle,
158
+ 'Numero': numero
159
+ })
160
+
161
+ if req.status_code == 200 and comprobar_errores(req.json()):
162
+ info_cadastre = json.loads(req.content)
163
+ cudnp = info_cadastre.get("consulta_dnplocResult", {}).get("control", {}).get("cudnp", 1)
164
+
165
+ if cudnp > 1:
166
+ raise ErrorServidorCatastro(mensaje="Esta parcela tiene varias referencias catastrales. Usa un objeto MetaParcela.")
167
+ else:
168
+ if 'lrcdnp' in info_cadastre.get('consulta_dnplocResult'):
169
+ self.rc = ''.join(info_cadastre.get('consulta_dnplocResult').get('lrcdnp').get('rcdnp')[0].get('rc').values())
170
+ elif 'bico' in info_cadastre.get('consulta_dnplocResult'):
171
+ self.rc = ''.join(info_cadastre.get('consulta_dnplocResult').get('bico').get('bi').get('idbi').get('rc').values())
172
+ self.__create_from_rc(self.rc)
173
+ elif 'lerr' in json.loads(req.content).get('consulta_dnplocResult') and json.loads(req.content)['consulta_dnplocResult']['lerr'][0]['cod'] == '43':
174
+ info_cadastre = json.loads(req.content)
175
+ raise Exception(f"Ese número no existe. Prueba con alguno de estos: {[num.get('num').get('pnp') for num in info_cadastre.get('consulta_dnplocResult').get('numerero').get('nump')]}")
176
+
177
+
178
+ else:
179
+ raise Exception('La calle no existe.')
180
+
181
+ def __init__(self, rc: str|None = None, provincia: int|str|None = None, municipio: int|str|None = None, poligono: int|None = None, parcela: int|None = None, tipo_via: str|None = None, calle: str|None = None, numero: str|None = None):
182
+ if rc:
183
+ self.rc = rc
184
+ self.__create_from_rc(rc)
185
+ elif provincia and municipio and poligono and parcela:
186
+ self.provincia = provincia
187
+ self.municipio = municipio
188
+ self.poligono = poligono
189
+ self.parcela = parcela
190
+ self.__create_from_parcel(provincia, municipio, poligono, parcela)
191
+ elif provincia and municipio and tipo_via and calle and numero:
192
+ self.provincia = provincia
193
+ self.municipio = municipio
194
+ self.calle = calle
195
+ self.numero = numero
196
+ self.__create_from_address(provincia, municipio, tipo_via, calle, numero)
197
+ else:
198
+ raise ValueError("No se ha proporcionado suficiente información para realizar la búsqueda")
199
+
200
+ class MetaParcela:
201
+ """
202
+ Clase que representa una MetaParcela, es decir, una gran parcela catastral con
203
+ varias referencias catastrales (Parcelas Catastrales más pequeñas).
204
+
205
+ Args:
206
+ rc (str|None): La referencia catastral de la MetaParcela.
207
+
208
+ provincia (int|str|None): El nombre de la provincia donde se encuentra la MetaParcela.
209
+ municipio (int|str|None): El nombre del municipio donde se encuentra la MetaParcela.
210
+ poligono (int|None): El número de polígono de la MetaParcela. Sólo se usa para buscar por parcela.
211
+ parcela (int|None): El número de parcela de la MetaParcela. Sólo se usa para buscar por parcela.
212
+ tipo_via (str|None): El tipo de vía de la dirección de la MetaParcela. Sólo se usa para buscar por dirección.
213
+ calle (str|None): El nombre de la calle de la dirección de la MetaParcela. Sólo se usa para buscar por dirección.
214
+ numero (str|None): El número de la dirección de la MetaParcela. Sólo se usa para buscar por dirección.
215
+ Attributes:
216
+ rc (str): La referencia catastral de la MetaParcela.
217
+ parcelas (list): Una lista de ParcelaCatastral que representan las parcelas que componen la MetaParcela.
218
+
219
+ """
220
+
221
+ def __create_from_rc(self, rc: str):
222
+ """Create an instance of InfoCatastral from a RC (Referencia Catastral) string."""
223
+ req1 = requests.get(f'{URL_BASE_CALLEJERO}/Consulta_DNPRC',
224
+ params={'RefCat': rc})
225
+
226
+ info_cadastre = json.loads(req1.content)
227
+ if comprobar_errores(info_cadastre):
228
+ self.parcelas = []
229
+ num_parcelas = info_cadastre.get("consulta_dnprcResult", {}).get("control", {}).get("cudnp", 1)
230
+ for idx in range(num_parcelas):
231
+ rc = ''.join(info_cadastre.get('consulta_dnprcResult').get('lrcdnp').get('rcdnp')[idx].get('rc').values())
232
+ self.parcelas.append(ParcelaCatastral(rc=rc))
233
+
234
+
235
+ def __create_from_parcel(self, provincia: str|None, municipio: str|None, poligono: str|None, parcela: str|None):
236
+ """Create an instance of InfoCatastral from a parcela string."""
237
+ req = requests.get(f'{URL_BASE_CALLEJERO}/Consulta_DNPPP',
238
+ params={
239
+ 'Provincia': provincia,
240
+ 'Municipio': municipio,
241
+ 'Poligono': poligono,
242
+ 'Parcela': parcela
243
+ })
244
+
245
+ info_cadastre = json.loads(req.content)
246
+ if comprobar_errores(info_cadastre):
247
+ self.parcelas = []
248
+ num_parcelas = info_cadastre.get("consulta_dnpppResult", {}).get("control", {}).get("cudnp", 1)
249
+ for idx in range(num_parcelas):
250
+ rc = ''.join(info_cadastre.get('consulta_dnpppResult').get('lrcdnp').get('rcdnp')[idx].get('rc').values())
251
+ self.parcelas.append(ParcelaCatastral(rc=rc))
252
+
253
+ def __create_from_address(self, provincia: str|None, municipio: str|None, tipo_via: str|None, calle: str|None, numero: str|None):
254
+ """Create an instance of InfoCatastral from an address string."""
255
+ info_calle = Calle(
256
+ municipio=Municipio(
257
+ provincia=provincia,
258
+ municipio=municipio
259
+ ),
260
+ tipo_via=tipo_via,
261
+ nombre_calle=calle
262
+ )
263
+
264
+ if info_calle:
265
+ req = requests.get(f'{URL_BASE_CALLEJERO}/Consulta_DNPLOC',
266
+ params={
267
+ 'Provincia': info_calle.municipio.provincia,
268
+ 'Municipio': info_calle.municipio.municipio,
269
+ 'Sigla': info_calle.tipo_via,
270
+ 'Calle': info_calle.calle,
271
+ 'Numero': numero
272
+ })
273
+
274
+ if req.status_code == 200 and comprobar_errores(req.json()):
275
+ info_cadastre = json.loads(req.content)
276
+ self.parcelas = []
277
+ num_parcelas = info_cadastre.get("consulta_dnplocResult", {}).get("control", {}).get("cudnp", 1)
278
+ for idx in range(num_parcelas):
279
+ rc = ''.join(info_cadastre.get('consulta_dnplocResult').get('lrcdnp').get('rcdnp')[idx].get('rc').values())
280
+ self.parcelas.append(ParcelaCatastral(rc=rc))
281
+
282
+ else:
283
+ raise Exception('La calle no existe.')
284
+
285
+ def __init__(self, rc: str|None = None, provincia: int|str|None = None, municipio: int|str|None = None, poligono: int|None = None, parcela: int|None = None, tipo_via: str|None = None, calle: str|None = None, numero: str|None = None):
286
+ if rc:
287
+ self.rc = rc
288
+ self.__create_from_rc(rc)
289
+ elif provincia and municipio and poligono and parcela:
290
+ self.provincia = provincia
291
+ self.municipio = municipio
292
+ self.poligono = poligono
293
+ self.parcela = parcela
294
+ self.__create_from_parcel(provincia, municipio, poligono, parcela)
295
+ elif provincia and municipio and tipo_via and calle and numero:
296
+ self.provincia = provincia
297
+ self.municipio = municipio
298
+ self.calle = calle
299
+ self.numero = numero
300
+ self.__create_from_address(provincia, municipio, tipo_via, calle, numero)
301
+ else:
302
+ raise ValueError("No se ha proporcionado suficiente información para realizar la búsqueda")
303
+
@@ -0,0 +1,29 @@
1
+ from ..utils.utils import listar_municipios
2
+
3
+ class Municipio:
4
+ """
5
+ Clase que representa un municipio.
6
+ Args:
7
+ provincia (str): El nombre de la provincia a la que pertenece el municipio.
8
+ municipio (str, optional): El nombre del municipio. Si no se proporciona, se lanzará una excepción con el municipio.
9
+ Attributes:
10
+ provincia (str): El nombre de la provincia a la que pertenece el municipio.
11
+ municipio (str): El nombre del municipio.
12
+ Raises:
13
+ Exception: Si no se especifica el municipio o si el municipio especificado no está disponible o si no se ha especificado completamente (te dará una lista de coincidencias).
14
+ """
15
+
16
+ def __init__(self, provincia: str, municipio: str|None = None):
17
+ municipios = listar_municipios(provincia=provincia,municipio=municipio)
18
+
19
+ if municipio:
20
+ if len(municipios) == 1:
21
+ self.provincia = provincia
22
+ self.municipio = municipios[0]
23
+ elif municipio.upper() in municipios:
24
+ self.provincia = provincia
25
+ self.municipio = municipio.upper()
26
+ else:
27
+ raise Exception(f"Error al asignar municipio. No has especificado el municipio completamente. Estos son los municipios disponibles con esa búsqueda: {','.join(municipios)}")
28
+ else:
29
+ raise Exception(f"Error al asignar municipio. No has especificado el municipio. Estos son los municipios disponibles: {','.join(municipios)}")
@@ -0,0 +1,4 @@
1
+ # ESCatastroLib/models/__init__.py
2
+ from .Calle import Calle
3
+ from .Municipio import Municipio
4
+ from .InfoCatastral import ParcelaCatastral, MetaParcela
@@ -0,0 +1,4 @@
1
+ # ESCatastroLib/utils/__init__.py
2
+ from .exceptions import *
3
+ from .statics import *
4
+ from .utils import *
@@ -0,0 +1,21 @@
1
+ class ErrorServidorCatastro(Exception):
2
+ """
3
+ Clase de excepción personalizada para errores relacionados con el servidor del Catastro.
4
+ Atributos:
5
+ - mensaje (str): Mensaje de error específico del servidor del Catastro.
6
+ """
7
+
8
+ def __init__(self, mensaje=''):
9
+ self.message = f'Error del Catastro. {mensaje}'
10
+ super().__init__(self.message)
11
+
12
+ def lanzar_excepcion(mensaje_error: str) -> Exception:
13
+ """
14
+ Lanza una excepción personalizada con el mensaje de error proporcionado.
15
+ Args:
16
+ mensaje_error (str): El mensaje de error que se incluirá en la excepción.
17
+ Returns:
18
+ Exception: La excepción personalizada con el mensaje de error.
19
+ """
20
+
21
+ return ErrorServidorCatastro(mensaje=mensaje_error)
@@ -0,0 +1,122 @@
1
+ URL_BASE_CALLEJERO = 'https://ovc.catastro.meh.es/OVCServWeb/OVCWcfCallejero/COVCCallejero.svc/json'
2
+ URL_BASE_GEOGRAFIA = 'http://ovc.catastro.meh.es/INSPIRE/wfsCP.aspx'
3
+ URL_BASE_CROQUIS_DATOS = f'https://www1.sedecatastro.gob.es/CYCBienInmueble/SECImprimirCroquisYDatos.aspx'
4
+
5
+ MAPEOS_PROVINCIAS = {
6
+ 'La Coruña': 'A Coruña',
7
+ 'Orense': 'Ourense',
8
+ 'Santa Cruz De Tenerife': 'S.C. Tenerife',
9
+ 'Las Palmas De Gran Canaria': 'Las Palmas',
10
+ 'Alicante': 'Alacant',
11
+ 'Almería': 'Almeria',
12
+ 'Cádiz': 'Cadiz',
13
+ 'Córdoba': 'Cordoba',
14
+ 'Gerona': 'Girona',
15
+ 'Castellón De La Plana': 'Castello',
16
+ 'Castellón': 'Castello',
17
+ 'Lérida': 'Lleida',
18
+ 'Málaga': 'Malaga',
19
+ 'León': 'Leon',
20
+ 'Ávila': 'Avila',
21
+ 'Cáceres': 'Caceres',
22
+ 'Baleares': 'Illes Balears',
23
+ 'Islas Baleares': 'Illes Balears',
24
+ 'Jaén': 'Jaen',
25
+ 'València': 'Valencia'
26
+ }
27
+
28
+ TIPOS_VIA = {
29
+ "AC": "ACCESO",
30
+ "AG": "AGREGADO",
31
+ "AL": "ALDEA, ALAMEDA",
32
+ "AN": "ANDADOR",
33
+ "AR": "AREA, ARRABAL",
34
+ "AU": "AUTOPISTA",
35
+ "AV": "AVENIDA",
36
+ "AY": "ARROYO",
37
+ "BJ": "BAJADA",
38
+ "BL": "BLOQUE",
39
+ "BO": "BARRIO",
40
+ "BQ": "BARRANQUIL",
41
+ "BR": "BARRANCO",
42
+ "CA": "CAÑADA",
43
+ "CG": "COLEGIO, CIGARRAL",
44
+ "CH": "CHALET",
45
+ "CI": "CINTURON",
46
+ "CJ": "CALLEJA, CALLEJON",
47
+ "CL": "CALLE",
48
+ "CM": "CAMINO, CARMEN",
49
+ "CN": "COLONIA",
50
+ "CO": "CONCEJO, COLEGIO",
51
+ "CP": "CAMPA, CAMPO",
52
+ "CR": "CARRETERA, CARRERA",
53
+ "CS": "CASERIO",
54
+ "CT": "CUESTA, COSTANILLA",
55
+ "CU": "CONJUNTO",
56
+ "CY": "CALEYA",
57
+ "CZ": "CALLIZO",
58
+ "DE": "DETRÁS",
59
+ "DP": "DIPUTACION",
60
+ "DS": "DISEMINADOS",
61
+ "ED": "EDIFICIOS",
62
+ "EM": "EXTRAMUROS",
63
+ "EN": "ENTRADA, ENSANCHE",
64
+ "EP": "ESPALDA",
65
+ "ER": "EXTRARRADIO",
66
+ "ES": "ESCALINATA",
67
+ "EX": "EXPLANADA",
68
+ "FC": "FERROCARRIL",
69
+ "FN": "FINCA",
70
+ "GL": "GLORIETA",
71
+ "GR": "GRUPO",
72
+ "GV": "GRAN VIA",
73
+ "HT": "HUERTA, HUERTO",
74
+ "JR": "JARDINES",
75
+ "LA": "LAGO",
76
+ "LD": "LADO, LADERA",
77
+ "LG": "LUGAR",
78
+ "MA": "MALECON",
79
+ "MC": "MERCADO",
80
+ "ML": "MUELLE",
81
+ "MN": "MUNICIPIO",
82
+ "MS": "MASIAS",
83
+ "MT": "MONTE",
84
+ "MZ": "MANZANA",
85
+ "PB": "POBLADO",
86
+ "PC": "PLACETA",
87
+ "PD": "PARTIDA",
88
+ "PI": "PARTICULAR",
89
+ "PJ": "PASAJE, PASADIZO",
90
+ "PL": "POLIGONO",
91
+ "PM": "PARAMO",
92
+ "PQ": "PARROQUIA, PARQUE",
93
+ "PR": "PROLONGACION, CONTINUAC.",
94
+ "PS": "PASEO",
95
+ "PT": "PUENTE",
96
+ "PU": "PASADIZO",
97
+ "PZ": "PLAZA",
98
+ "QT": "QUINTA",
99
+ "RA": "RACONADA",
100
+ "RB": "RAMBLA",
101
+ "RC": "RINCON, RINCONA",
102
+ "RD": "RONDA",
103
+ "RM": "RAMAL",
104
+ "RP": "RAMPA",
105
+ "RR": "RIERA",
106
+ "RU": "RUA",
107
+ "SA": "SALIDA",
108
+ "SC": "SECTOR",
109
+ "SD": "SENDA",
110
+ "SL": "SOLAR",
111
+ "SN": "SALON",
112
+ "SU": "SUBIDA",
113
+ "TN": "TERRENOS",
114
+ "TO": "TORRENTE",
115
+ "TR": "TRAVESIA",
116
+ "UR": "URBANIZACION",
117
+ "VA": "VALLE",
118
+ "VD": "VIADUCTO",
119
+ "VI": "VIA",
120
+ "VL": "VIAL",
121
+ "VR": "VEREDA"
122
+ }
@@ -0,0 +1,102 @@
1
+ import requests
2
+ import json
3
+
4
+ from .statics import URL_BASE_CALLEJERO, MAPEOS_PROVINCIAS, TIPOS_VIA
5
+ from .exceptions import lanzar_excepcion
6
+
7
+ def comprobar_errores(respuesta: dict):
8
+ """
9
+ Comprueba si la respuesta contiene errores.
10
+
11
+ Args:
12
+ respuesta (dict): El diccionario de respuesta.
13
+
14
+ Raises:
15
+ lanzar_excepcion: Si se encuentra un error en la respuesta.
16
+
17
+ Returns:
18
+ bool: True si no se encuentran errores, False en caso contrario.
19
+ """
20
+ # Check if the response contains the expected structure
21
+ if len(list(respuesta.values())) > 0:
22
+ if list(respuesta.values())[0] is not None and 'lerr' in list(respuesta.values())[0].keys():
23
+ if 'err' in list(respuesta.values())[0]['lerr']:
24
+ raise lanzar_excepcion(mensaje_error=list(respuesta.values())[0]['lerr']['err'][0]['des'])
25
+ else:
26
+ raise lanzar_excepcion(mensaje_error=list(respuesta.values())[0]['lerr'][0]['des'])
27
+ return True
28
+
29
+ def listar_provincias():
30
+ """
31
+ Obtiene una lista de provincias.
32
+ Returns:
33
+ list: Una lista de nombres de provincias.
34
+ Raises:
35
+ None
36
+ """
37
+
38
+ response = requests.get(f'{URL_BASE_CALLEJERO}/ObtenerProvincias')
39
+ return [provincia.get('np') for provincia in response.json().get('consulta_provincieroResult').get('provinciero').get('prov')] if comprobar_errores(response.json()) else []
40
+
41
+ def listar_municipios(provincia: str, municipio: str|None = None):
42
+
43
+ """
44
+ Obtiene una lista de municipios de España.
45
+ Args:
46
+ provincia (str): El nombre de la provincia. Preferentemente en mayúsculas o capitalizado.
47
+ municipio (str, optional): El nombre del municipio. Por defecto es None.
48
+ Returns:
49
+ List[str]: Una lista de nombres de municipios.
50
+ Raises:
51
+ Exception: Si la provincia no existe. Muestra un mensaje con las provincias disponibles.
52
+ """
53
+
54
+ if provincia and provincia.capitalize() not in MAPEOS_PROVINCIAS and provincia.upper() not in listar_provincias():
55
+ raise Exception(f'La provincia {provincia} no existe. Las provincias de España son: {listar_provincias()}')
56
+
57
+ response = requests.get(f'{URL_BASE_CALLEJERO}/ObtenerMunicipios',
58
+ params={
59
+ 'provincia' : MAPEOS_PROVINCIAS.get(provincia.capitalize())
60
+ if MAPEOS_PROVINCIAS.get(provincia.capitalize(),None) != None
61
+ else provincia ,
62
+ 'municipio': municipio
63
+ })
64
+ if response.status_code == 200 and comprobar_errores(response.json()):
65
+ mun_dict_raw = json.loads(response.content)
66
+ return [mun.get('nm') for mun in mun_dict_raw.get('consulta_municipieroResult').get('municipiero').get('muni')]
67
+ else:
68
+ return []
69
+
70
+
71
+ def listar_tipos_via():
72
+ """
73
+ Retorna una lista de los tipos de vía disponibles.
74
+ Returns:
75
+ list: Una lista de los tipos de vía disponibles.
76
+ """
77
+
78
+ return TIPOS_VIA
79
+
80
+ def listar_calles(provincia: str, municipio: str):
81
+ """
82
+ Devuelve una lista de calles para una provincia y municipio dados.
83
+ Args:
84
+ provincia (str): El nombre de la provincia.
85
+ municipio (str): El nombre del municipio.
86
+ Returns:
87
+ list: Una lista de calles en formato "tipo de vía nombre de vía".
88
+ """
89
+
90
+ provincia_final = MAPEOS_PROVINCIAS.get(provincia.capitalize()) if provincia.capitalize() in MAPEOS_PROVINCIAS.keys() else provincia
91
+ if provincia_final.upper() in listar_provincias() and municipio.upper() in listar_municipios(provincia=provincia_final):
92
+ response = requests.get(f'{URL_BASE_CALLEJERO}/ObtenerCallejero',
93
+ params={
94
+ 'Provincia': provincia_final,
95
+ 'Municipio': municipio
96
+ })
97
+ if response.status_code == 200 and comprobar_errores(response.json()):
98
+ calles_dict_raw = json.loads(response.content)
99
+ return [f"{calle.get('dir').get('tv')} {calle.get('dir').get('nv')}" for calle in calles_dict_raw.get('consulta_callejeroResult').get('callejero').get('calle')]
100
+ else:
101
+ return []
102
+ else: return []
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Iván Valero Rodríguez
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,288 @@
1
+ Metadata-Version: 2.2
2
+ Name: ESCatastroLib
3
+ Version: 0.0.1rc0
4
+ Summary: Description
5
+ Home-page: https://github.com/IvanitiX/ESCatastroLib
6
+ Author: Iván V.R
7
+ Author-email: IvanVR@protonmail.com
8
+ License: Apache License, Version 2.0
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Topic :: Software Development :: Build Tools
12
+ Classifier: Programming Language :: Python :: 3
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: requests
16
+ Requires-Dist: xml2dict
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: home-page
23
+ Dynamic: license
24
+ Dynamic: requires-dist
25
+ Dynamic: summary
26
+
27
+ # ESCatastroLib
28
+
29
+ La librería ESCatastroLib proporciona una interfaz sencilla para consultar el Catastro de España y obtener información geográfica precisa. Con esta librería, puedes acceder a datos como la ubicación de parcelas, características de construcción y valores geográficos.
30
+
31
+ # Clases
32
+
33
+ ## Clase Municipio
34
+
35
+ Representa un municipio (ciudad o pueblo).
36
+
37
+ **Atributos/Inputs del constructor**
38
+
39
+ `provincia (str)`: El nombre de la provincia donde se encuentra el municipio. Un valor por
40
+ defecto se establece y se puede proporcionar un valor diferente si es necesario.
41
+
42
+ `municipio (str, opcional)`: El nombre del municipio. Si no se proporciona al crear una instancia, se
43
+ lanzará una excepción. Si se especifica, debe coincidir al menos parcialmente con el nombre de un municipio válido encontrado en la base de datos o fuente de datos del sistema.
44
+
45
+ **Excepciones**
46
+
47
+ `Exception`: Si no se especifica el `municipio` o si es inválido, o si no corresponde a un municipio válido
48
+ en la base de datos del sistema. Se lanzará una excepción con la lista de municipios en ese caso.
49
+
50
+ ## Clase Calle
51
+
52
+ La clase `Calle` es una entidad que representa una calle.
53
+
54
+ **Atributos/Inputs del constructor:**
55
+
56
+ `municipio (Municipio)` : Objeto que representa el Municipio al que pertenece la calle.
57
+
58
+ `nombre_calle (str, opcional)` : El nombre de la calle asignada.
59
+
60
+ `tipo_via (str, opcional)` : El tipo de vía de la calle asignada. Se trata de una serie de siglas que puedes consultar en `utils.listar_tipos_via()`
61
+
62
+ **Excepciones**
63
+
64
+ `Exception`: Si no existe la calle, o la calle tiene más de un tipo de vía. Devuelve una lista de calles en formato `TipoVia NombreCalle`
65
+
66
+ ## Clase ParcelaCatastral
67
+
68
+ Representa una parcela catastral.
69
+
70
+
71
+ **Inputs del constructor:**
72
+
73
+ * `rc (str, opcional)`: La referencia catastral de la parcela. Por defecto es `None`. Puede ser proporcionada
74
+ sola; también puede haber otros parámetros para buscar una parcela específica en el sistema.
75
+ * `provincia (str, opcional)`: El nombre de la provincia. Por defecto es `None`. Se usa para
76
+ buscar por dirección o parcela.
77
+ * `municipio (str, opcional)`: El nombre del municipio. Por defecto es `None`. Se usa para buscar
78
+ por dirección o parcela.
79
+
80
+
81
+ * `poligono (int, opcional)`: El número del polígono. Por defecto es `None` y puede ser específico para zonas rurales.
82
+ * `parcela (int, opcional)`: El número de la parcela. Por defecto es `None` y se usa para buscar zonas rurales.
83
+
84
+
85
+
86
+ * `tipo_via (str, opcional)`: El tipo de carretera en la dirección. Por defecto es `None` y es útil al buscar
87
+ direcciones urbanas.
88
+ * `calle (str, opcional)`: El nombre de la calle en la dirección. Por defecto es `None` y es útil para
89
+ encontrar ubicaciones urbanas
90
+ * `numero (str, opcional)`: El número de la calle en la dirección. Por defecto es `None` y se usa para encontrar
91
+ ubicaciones urbanas por número.
92
+
93
+ **Excepciones:**
94
+ * `ValueError`: Si no has proporcionado suficiente información para realizar la búsqueda, o si el RC hace
95
+ referencia a una MetaParcela.
96
+ * `ErrorServidorCatastro`: Si hay un error con la base de datos del Catastral Server.
97
+
98
+
99
+ **Atributos:**
100
+
101
+ * `rc (str)`: La referencia catastral de la parcela.
102
+ * `provincia (str)`: El nombre de la provincia.
103
+ * `municipio (str)`: El nombre del municipio.
104
+ * `poligono (int)`: El número del polígono. Solo se usa para terrenos rurales.
105
+ * `parcela (int)`: El número de la parcela. Solo se usa para terrenos rurales.
106
+ * `tipo_via (str)`: El tipo de carretera en la dirección.
107
+ * `calle (str)`: El nombre de la calle en la dirección.
108
+ * `numero (str)`: El número de la calle en la dirección.
109
+ * `url_croquis (str)`: La URL del croquis de la parcela.
110
+ * `tipo (str)`: El tipo de terreno (urbano o rural).
111
+ * `antiguedad (str)`: La edad de la parcela (solo en lotes urbanos)
112
+ * `uso (str)`: El uso de la parcela (solo en lotes urbanos)
113
+ * `nombre_paraje (str)`: El nombre del área, solo se usa para terrenos rurales.
114
+ * `regiones (list)`: Una lista de regiones en la parcela con una descripción y superficie.
115
+ * `geocentro (dict)`: Las coordenadas del centro de la parcela. (Latitud y longitud)
116
+ * `geometria (list)`: Una lista de puntos que representan la geometría de la parcela. (Latitud y longitud)
117
+
118
+
119
+ ## Clase MetaParcela
120
+
121
+ Representa una MetaParcela, es decir, una gran parcela catastral con varias referencias catastrales (Parcels
122
+ Catastrales más pequeñas).
123
+
124
+
125
+ **Atributos/Inputs del constructor:**
126
+
127
+ * `rc (str|None)`: La referencia catastral de la MetaParcela. Puede ser proporcionada como `None`.
128
+ * `provincia (str|None)`: El nombre de la provincia donde se encuentra la MetaParcela. Por
129
+ defecto, es `None`, lo que permite usar nombres generales.
130
+ * `municipio (str|None)`: El nombre del municipio donde se encuentra la MetaParcela. Por
131
+ defecto, es `None`, lo que permite usar nombres generales.
132
+ * `poligono (int|None)`: El número del polígono en el que se encuentra la MetaParcela. Se utiliza para encontrar
133
+ una parcela específica.
134
+ * `parcela (int|None)`: El número de parcelas dentro de la MetaParcela. Se utiliza para encontrar una parcela
135
+ específica.
136
+ * `tipo_via (str|None)`: Tipo de camino en la dirección de la MetaParcela. Se usa para encontrar una parcela
137
+ específica.
138
+ * `calle (str|None)`: Nombre de la calle de la MetaParcela. Se usa para encontrar una parcela específica.
139
+ * `numero (str|None)`: Número de casa de la MetaParcela.
140
+
141
+ **Atributos:**
142
+
143
+ * `rc (str)`: La referencia catastral de la MetaParcela.
144
+ * `parcelas (list)`: Una lista de ParcelaCatastral que representan las parcelas que componen la MetaParcela.
145
+
146
+
147
+
148
+ # Funciones útiles
149
+
150
+ ## `comprobar_errores()`
151
+
152
+ Comprueba si la respuesta contiene errores.
153
+
154
+ **Argumentos**:
155
+ * `respuesta (dict)`: El diccionario de respuesta.
156
+
157
+ **Excepciones**:
158
+ * El que venga de `lanzar_excepcion` (`ErrorServidorCatastro`): Si se encuentra un error en la respuesta.
159
+
160
+ **Devuelve**:
161
+ * `True` si no se encuentran errores
162
+
163
+ ## `listar_provincias()`
164
+
165
+ Obtiene una lista de provincias.
166
+
167
+ **Devuelve**:
168
+ * `list`: Una lista de nombres de provincias.
169
+
170
+ ## `listar_municipios()`
171
+
172
+ Obtiene una lista de municipios de España.
173
+
174
+ **Argumentos**:
175
+ * `provincia (str)`: El nombre de la provincia. Preferentemente en mayúsculas o capitalizado.
176
+ * `municipio (str, optional)`: El nombre del municipio. Por defecto es None.
177
+
178
+ **Devuelve**:
179
+ * `List[str]`: Una lista de nombres de municipios.
180
+
181
+ **Excepciones**:
182
+ * `Exception`: Si la provincia no existe. Muestra un mensaje con las provincias disponibles.
183
+
184
+ ## `listar_tipos_via()`
185
+
186
+ Retorna una lista de los tipos de vía disponibles.
187
+
188
+ **Devuelve**:
189
+ * `list`: Una lista de los tipos de vía disponibles.
190
+
191
+ ## `listar_calles()`
192
+
193
+ Devuelve una lista de calles para una provincia y municipio dados.
194
+
195
+ **Argumentos**:
196
+ * `provincia (str)`: El nombre de la provincia.
197
+ * `municipio (str)`: El nombre del municipio.
198
+
199
+ **Devuelve**:
200
+ * `list`: Una lista de calles en formato "tipo de vía nombre de vía".
201
+
202
+ # Y esta librería... ¿Cómo se usa?
203
+ ¡Buena pregunta! Os dejo algunos ejemplos:
204
+
205
+ ```python
206
+ from ESCatastroLib import Municipio, Calle, ParcelaCatastral, MetaParcela
207
+ from ESCatastroLib.utils import listar_provincias, listar_tipos_via, listar_calles, listar_municipios
208
+
209
+ print(listar_provincias())
210
+ # > ['A CORUÑA', 'ALACANT', 'ALBACETE', 'ALMERIA', 'ASTURIAS', 'AVILA', 'BADAJOZ', ...]
211
+
212
+ print(listar_tipos_via())
213
+ # > {'AC': 'ACCESO', 'AG': 'AGREGADO', 'AL': 'ALDEA, ALAMEDA', 'AN': 'ANDADOR', 'AR': 'AREA, ARRABAL', 'AU': 'AUTOPISTA', 'AV': 'AVENIDA', ... }
214
+
215
+ print(listar_municipios(provincia='Granada'))
216
+ # > ['AGRON', 'ALAMEDILLA', 'ALBOLOTE', 'ALBONDON', 'ALBUÑAN', 'ALBUÑOL', 'ALBUÑUELAS', 'ALDEIRE', ...]
217
+
218
+ print(listar_municipios(provincia='Granada', municipio='B'))
219
+ # > ['ALBOLOTE', 'ALBONDON', 'ALBUÑAN', 'ALBUÑOL', 'ALBUÑUELAS', 'BAZA', 'BEAS DE GRANADA', 'BEAS DE GUADIX', ...]
220
+
221
+ print(listar_calles(provincia='Granada', municipio = 'Baza'))
222
+ # > ['CL PARAISO (BAU)', 'CL A ALTOS', 'CL A PAVON', 'CL ABAD NAVARRO', 'PZ ABASTOS', 'CL ABEDUL', 'CL ABELARDO LOPEZ DE AYALA', 'CL ABENAMAR', 'CL ACEQUITA', 'CL ADARVE MONJAS', 'CL ADMINISTRADOR', 'TR ADUANA', 'CL ADUANA', 'CL AGUILA', 'CL AIRE', 'CL AIXA', ...]
223
+
224
+ municipio = Municipio(provincia='Granada')
225
+ # [!] Exception: Error al asignar municipio. No has especificado el municipio. Estos son los municipios disponibles: AGRON,ALAMEDILLA,ALBOLOTE,ALBONDON ...
226
+
227
+ municipio = Municipio(provincia='Granada', municipio='B')
228
+ # [!] Exception: Error al asignar municipio. No has especificado el municipio completamente. Estos son los municipios disponibles con esa búsqueda: ALBOLOTE,ALBONDON,ALBUÑAN,ALBUÑOL,ALBUÑUELAS,BAZA,BEAS DE GRANADA, ...
229
+
230
+ municipio = Municipio(provincia='Granada', municipio='Baza')
231
+ # [OK] {'provincia': 'Granada', 'municipio': 'BAZA'}
232
+
233
+ calle = Calle(municipio=municipio)
234
+ # [!] Exception: Error al asignar calle. No has especificado la calle. Estas son las calles disponibles: CL PARAISO (BAU),CL A ALTOS,CL A PAVON,CL ABAD NAVARRO,PZ ABASTOS,CL ABEDUL,CL ABELARDO LOPEZ DE AYALA, ...
235
+
236
+ calle = Calle(municipio=municipio, nombre_calle= 'M')
237
+ # [!] Exception: Error al asignar calle. No has especificado la calle completamente, o ese nombre está en varios lados (indica el tipo de vía que aparezca al principio de la vía como PZ o CL). Estas son las calles disponibles con esa búsqueda: CL ABENAMAR,CL ADARVE MONJAS,CL ADMINISTRADOR,CL ALAMEDA,CL ALAMILLOS,CL ALAMILLOS ALTOS,CL ALAMILLOS BAJOS,CL ALAMO,CL ALGAMASILLA,CL ALHAMBRA,...
238
+
239
+ calle = Calle(municipio=municipio, nombre_calle='Mayor', tipo_via='PL')
240
+ # [!] ErrorServidorCatastro: Error del Catastro. NO HAY COINCIDENCIAS EN LA BÚSQUEDA DE VÍAS
241
+
242
+ calle = Calle(municipio=municipio, nombre_calle='Mayor', tipo_via='PZ')
243
+ # [OK] {'calle': 'MAYOR', 'tipo_via': 'PZ', 'municipio': <ESCatastroLib.models.Municipio.Municipio at 0x7f0075209e10>}
244
+
245
+ pc = ParcelaCatastral(rc='22113U490470815583UK')
246
+ # [!] ErrorServidorCatastro: Error del Catastro. NO EXISTE NINGÚN INMUEBLE CON LOS PARÁMETROS INDICADOS
247
+
248
+ pc = ParcelaCatastral(rc='28067A023001490000FJ')
249
+ # [OK] {'rc': '28067A023001490000FJ', 'url_croquis': 'https://www1.sedecatastro.gob.es/CYCBienInmueble/SECImprimirCroquisYDatos.aspx?refcat=28067A023001490000FJ', 'municipio': 'GUADALIX DE LA SIERRA', 'provincia': 'MADRID', 'tipo': 'Rústico', 'parcela': '149', 'poligono': '23', 'nombre_paraje': 'PE¥ARRUBIA', 'regiones': [{'descripcion': 'PRADOS O PRADERAS', 'superficie': '250266'}, {'descripcion': 'MONTE BAJO', 'superficie': '187652'}, {'descripcion': 'PASTOS', 'superficie': '1814'}], 'geocentro': {'x': '40.76845', 'y': '-3.672895'}, 'geometria': [{'x': '40.764879', 'y': '-3.678524'}, {'x': '40.765874', 'y': '-3.678059'}, ...], 'superficie': 439732.0}
250
+
251
+ pc = ParcelaCatastral(rc='1541506VK4714B0002PK')
252
+ # [OK] {'rc': '1541506VK4714B0002PK', 'url_croquis': 'https://www1.sedecatastro.gob.es/CYCBienInmueble/SECImprimirCroquisYDatos.aspx?refcat=1541506VK4714B0002PK', 'municipio': 'MADRID', 'provincia': 'MADRID', 'tipo': 'Urbano', 'calle': 'CL ALFONSO XII', 'numero': '34', 'antiguedad': '1915', 'uso': 'Almacen-Estacionamiento.Uso Residencial', 'regiones': [{'descripcion': 'APARCAMIENTO', 'superficie': '37'}, {'descripcion': 'ELEMENTOS COMUNES', 'superficie': '2'}], 'geocentro': {'x': '40.414193', 'y': '-3.689266'}, 'geometria': [{'x': '40.414358', 'y': '-3.689164'}, {'x': '40.414359', 'y': '-3.689094'}, {'x': '40.414288', 'y': '-3.689092'}, ...], 'superficie': 39.0}
253
+
254
+ pc = ParcelaCatastral(provincia='Granada', municipio='Baza', poligono=16, parcela=128)
255
+ # [OK] {'provincia': 'GRANADA', 'municipio': 'BAZA', 'poligono': '16', 'parcela': '128', 'rc': '18024A016001280000GY', 'url_croquis': 'https://www1.sedecatastro.gob.es/CYCBienInmueble/SECImprimirCroquisYDatos.aspx?refcat=18024A016001280000GY', 'tipo': 'Rústico', 'nombre_paraje': 'BAICO', 'regiones': [{'descripcion': 'LABOR O LABRADÍO REGADÍO', 'superficie': '14608'}], 'geocentro': {'x': '37.544352', 'y': '-2.742683'}, 'geometria': [{'x': '37.543611', 'y': '-2.74347'}, {'x': '37.543717', 'y': '-2.743522'}, {'x': '37.543945', 'y': '-2.743435'}, ...], 'superficie': 14608.0}
256
+
257
+
258
+ pc = ParcelaCatastral(provincia='Madrid', municipio='Madrid', poligono='1', parcela='1')
259
+ # [!] ErrorServidorCatastro: Error del Catastro. Esta parcela tiene varias referencias catastrales. Usa un objeto MetaParcela.
260
+
261
+ mp = MetaParcela(provincia='Madrid', municipio='Madrid', poligono='1', parcela='1')
262
+ # [OK] {'provincia': 'Madrid', 'municipio': 'Madrid', 'poligono': '1', 'parcela': '1', 'parcelas': [<ESCatastroLib.models.InfoCatastral.ParcelaCatastral object at 0x7f61b2298040>, <ESCatastroLib.models.InfoCatastral.ParcelaCatastral object at 0x7f61b13407f0>, <ESCatastroLib.models.InfoCatastral.ParcelaCatastral object at 0x7f61b223a830>, <ESCatastroLib.models.InfoCatastral.ParcelaCatastral object at 0x7f61b223a350>, <ESCatastroLib.models.InfoCatastral.ParcelaCatastral object at 0x7f61b13400a0>]}
263
+
264
+ pc = ParcelaCatastral(provincia='Granada', municipio='Guadix', tipo_via='CL', calle='Largacha', numero=6)
265
+ # [!] ErrorServidorCatastro: Error del Catastro. Esta parcela tiene varias referencias catastrales. Usa un objeto MetaParcela.
266
+
267
+
268
+ pc = ParcelaCatastral(provincia='Granada', municipio='Guadix', tipo_via='PZ', calle='Catedral', numero=1)
269
+ # [OK] {'provincia': 'GRANADA', 'municipio': 'GUADIX', 'calle': 'PZ CATEDRAL', 'numero': '1', 'rc': '8085801VG8288E0001FA', 'url_croquis': 'https://www1.sedecatastro.gob.es/CYCBienInmueble/SECImprimirCroquisYDatos.aspx?refcat=8085801VG8288E0001FA', 'tipo': 'Urbano', 'antiguedad': '1750', 'uso': 'Religioso', 'regiones': [{'descripcion': 'RELIGIOSO', 'superficie': '3308'}], 'geocentro': {'x': '37.301262', 'y': '-3.136249'}, 'geometria': [{'x': '37.301298', 'y': '-3.136662'}, {'x': '37.301316', 'y': '-3.136699'}, {'x': '37.301376', 'y': '-3.136711'}, ...], 'superficie': 3308.0}
270
+
271
+ mp = MetaParcela(provincia='Granada', municipio='Guadix', tipo_via='CL', calle='Largacha', numero=6)
272
+ # [OK] {'provincia': 'Granada', 'municipio': 'Guadix', 'calle': 'Largacha', 'numero': 6, 'parcelas': [<ESCatastroLib.models.InfoCatastral.ParcelaCatastral object at 0x7ff4441944c0>, <ESCatastroLib.models.InfoCatastral.ParcelaCatastral object at 0x7ff44507e770>, <ESCatastroLib.models.InfoCatastral.ParcelaCatastral object at 0x7ff444194160>, <ESCatastroLib.models.InfoCatastral.ParcelaCatastral object at 0x7ff44507e110>]}
273
+
274
+ ```
275
+
276
+ # ¿Cómo puedo contribuir?
277
+ Sigue las instrucciones de CONTRIBUTING.md y el Código de Conducta.
278
+
279
+ # Agradecimientos
280
+ - Al Catastro por hacer un Endpoint público.
281
+ - A GISCE-TI por currarse [una librería similar][1], basándose en los endpoints JSON.
282
+ - A mi abuelo y mi tío por pedirme que os eche una mano buscando tierras.
283
+ - A [Juanlu Cano][2] por darme la idea de extender el primer concepto en la PyConES para convertirlo en esta librería.
284
+ - A [Jaime Gómez-Obregón][3] por animar de forma muuuy indirecta a "hackear las Administraciones públicas".
285
+
286
+ [1]: https://github.com/gisce/pycatastro
287
+ [2]: https://github.com/astrojuanlu
288
+ [3]: https://github.com/JaimeObregon
@@ -0,0 +1,14 @@
1
+ ESCatastroLib/__init__.py,sha256=f1B_sHzinoIwapgkXv572FJbBfX5gkpyMC20JsHkKt4,143
2
+ ESCatastroLib/models/Calle.py,sha256=Sh612v87p0Zd2Etso5j-b0TABQNSU5b8XD2JhTfEzTQ,2734
3
+ ESCatastroLib/models/InfoCatastral.py,sha256=zkm_ep6eCQ7EM2cFPBbFEq62YDmY7SlE8x_8VYw2j6U,18075
4
+ ESCatastroLib/models/Municipio.py,sha256=5vTGUPCM6iy703FY_xp2EjorF6XZuZY8nU2_57p-yeM,1533
5
+ ESCatastroLib/models/__init__.py,sha256=Y8nN1Qp3_-VX7njuXwFWSq-62clHj878miEQGnzNXlc,149
6
+ ESCatastroLib/utils/__init__.py,sha256=kQj0ORkR_JMgwWgGi73APqn3p-UQipiuMY1QaBBmkLs,106
7
+ ESCatastroLib/utils/exceptions.py,sha256=YM3AuKHZ61SYgpmtYFz9n7JavdEOq2mLwyk2VzIol5A,759
8
+ ESCatastroLib/utils/statics.py,sha256=jXPmMIvLexok81xPYMhlgHr4DHYu9kCwrnzFRyBAriw,3121
9
+ ESCatastroLib/utils/utils.py,sha256=2P5w4jIIMlmR13Ev0343ZCO5Cnd5rAvsv3_kstbwHic,4358
10
+ ESCatastroLib-0.0.1rc0.dist-info/LICENSE,sha256=kgDY5GRu9WGoKk_0F0iYmXuLmGiZ9hgtReHhCfJBWr8,11319
11
+ ESCatastroLib-0.0.1rc0.dist-info/METADATA,sha256=i8191CJSkEI7w6NAHy_5mPQ-chs5mJ39Jg3d1H5wXbs,15695
12
+ ESCatastroLib-0.0.1rc0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
13
+ ESCatastroLib-0.0.1rc0.dist-info/top_level.txt,sha256=_tBtZfZum8_ZkPQV72uqQIRriwkWAY56Pr_Ha-OYGRI,14
14
+ ESCatastroLib-0.0.1rc0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.8.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ ESCatastroLib