Successfully reported this slideshow.
Your SlideShare is downloading. ×

Aplicaciones geográficas con Django - No solo de Javascript viven los mapas

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Sig
Sig
Loading in …3
×

Check these out next

1 of 43 Ad

Aplicaciones geográficas con Django - No solo de Javascript viven los mapas

Download to read offline

La 'ubicación' es una de las variables más importantes en cualquier problema, y es una de las más complicadas de manejar.

Django - sin ser un servidor geográfico de primera clase - proporciona una buena plataforma para incorporar el "dónde" en nuestras aplicaciones.

Presentaremos - de forma práctica - las capacidades geográficas de Django (acceso a BB.DD espaciales, consultas geográficas) y sus limitaciones

La 'ubicación' es una de las variables más importantes en cualquier problema, y es una de las más complicadas de manejar.

Django - sin ser un servidor geográfico de primera clase - proporciona una buena plataforma para incorporar el "dónde" en nuestras aplicaciones.

Presentaremos - de forma práctica - las capacidades geográficas de Django (acceso a BB.DD espaciales, consultas geográficas) y sus limitaciones

Advertisement
Advertisement

More Related Content

Similar to Aplicaciones geográficas con Django - No solo de Javascript viven los mapas (20)

Recently uploaded (20)

Advertisement

Aplicaciones geográficas con Django - No solo de Javascript viven los mapas

  1. 1. Aplicaciones Geográficas con Django “No sólo de Javascript viven los mapas”
  2. 2. Agenda × Geo (GIS) × Django × GeoDjango
  3. 3. GIS Geographic Information Systems
  4. 4. El mapa de John Snow
  5. 5. El mapa de John Snow https://carto.com/blog/game-of-thrones-basemap/ NOP!
  6. 6. El mapa de John Snow
  7. 7. El mapa John Snow
  8. 8. Características de los GIS
  9. 9. Geometrías Point Line Multipoint Multiline Polygon Multipolygon GeometryCollection
  10. 10. Formatos de entrada
  11. 11. Representación de los datos http://www.tysmagazine.com/los-sig-raster-herramienta-de-analisis-medioambiental-y-territorial/
  12. 12. Proyecciones y sistemas de coordenadas https://2012books.lardbucket.org/books/geographic-information-system-basics/s06-02-map-scale-coordinate-systems-a.html
  13. 13. Proyecciones y sistemas de coordenadas Mercator vs Peters https://en.wikipedia.org/wiki/List_of_map_projections
  14. 14. Django “The Web framework for perfectionists with deadlines”
  15. 15. “Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design
  16. 16. Urls Django Templates Views Models ORM
  17. 17. GeoDjango
  18. 18. “Intends to be a world-class geographic Web framework
  19. 19. GeoDjango Geodatabases Librerías geoespaciales
  20. 20. Integración con GeoDatabases
  21. 21. Geodatabases ¡1er Premio! ¡2o Premio!
  22. 22. Librerías Geoespaciales
  23. 23. ¿Por qué? × Aprovecha la fama de librerías open source ampliamente reconocidas × Utiliza SWIG y ctypes para aprovechar la funcionalidad en C de estas librerías × El uso de librerías en C permite un alto grado de compatibilidad multiplataforma
  24. 24. Librerías geoespaciales × GEOS × GDAL × GeoIP (BSD-licensed)
  25. 25. GEOS Geometry Engine Open Source
  26. 26. GEOS × Biblioteca en C ++ para realizar operaciones geométricas × Es la representación de geometría interna por defecto utilizada por GeoDjango × Licencia de BSD para las rutinas de geometría de GEOS, implementada puramente en Python usando ctypes
  27. 27. GEOS >>> pnt = GEOSGeometry('POINT(5 23)') # WKT >>> pnt = GEOSGeometry('010100000000000000000014400000000000003740') # HEX >>> pnt = GEOSGeometry('{ "type": "Point", "coordinates": [ 5.000000, 23.000000 ] }') # GeoJSON × Creando geometrías >>> pnt = Point(5, 23) >>> ring = LinearRing((0, 0), (0, 50), (50, 50), (50, 0), (0, 0)) >>> poly = Polygon(ring) >>> print poly.contains(pnt) True
  28. 28. GEOS >>> pnt = Point(5, 23) >>> [coord for coord in pnt] [5.0, 23.0] × Las geometrías son Pythonicas >>> line = LineString((0, 0), (0, 50), (50, 50), (50, 0), (0, 0)) >>> line[-2] (50.0, 0.0)
  29. 29. GDAL Geospatial Data Abstraction Library
  30. 30. GDAL × La navaja suiza de los datos GIS × Utiliza la OGR Simple Features Library, especializada en la lectura y escritura de datos en variedad de formatos estándar × Muy potente en la transformación de coordenadas espaciales
  31. 31. GDAL >>> from django.contrib.gis.gdal import DataSource >>> ds = DataSource('/path/to/your/cities.shp')>>> ds.layer_count # This file only contains one layer 1 × Carga de ficheros de datos >>> from django.contrib.gis.gdal import GDALRaster >>> rst = GDALRaster('/path/to/your/raster.tif', write=False)>>> rst.width, rst.height # This file has 163 x 174 pixels (163, 174)
  32. 32. GDAL >>> wkt = 'GEOGCS["WGS 84", DATUM["WGS_1984, AUTHORITY["EPSG","4326"]]') >>> srs = SpatialReference(wkt) # could also use 'WGS84', or 4326 >>> print(srs['GEOGCS']) WGS 84 >>> print(srs['DATUM']) WGS_1984 >>> print(srs['AUTHORITY']) EPSG >>> ct = CoordTransform(SpatialReference('WGS84'), SpatialReference('NAD83')) >>> for feat in layer: ... geom = feat.geom # getting clone of feature geometry ... geom.transform(ct) # transforming × Sistemas de coordenadas
  33. 33. GeoIP
  34. 34. GeoIP × Biblioteca para trabajar con información geográfica y de red basada en direcciones IP × La geolocalización IP es inherentemente imprecisa. Las ubicaciones están a menudo cerca del centro de la población
  35. 35. GeoIP >>> from django.contrib.gis.geoip import GeoIP >>> g = GeoIP() >>> g.country('google.com') {'country_code': 'US', 'country_name': 'United States'} >>> g.city('72.14.207.99') {'area_code': 650, 'city': 'Mountain View', 'country_code': 'US', 'country_code3': 'USA', 'country_name': 'United States', 'dma_code': 807, 'latitude': 37.419200897216797, 'longitude': -122.05740356445312, 'postal_code': '94043', 'region': 'CA'}
  36. 36. GeoDjango en acción
  37. 37. Modelos from django.contrib.gis.db import models class Lakes(models.Model): name = models.CharField(max_length=100) rate = models.IntegerField() geom = models.MultiPolygonField() × models.py
  38. 38. LayerMapping import os from django.contrib.gis.utils import LayerMapping from land.models import Lakes lakes_mapping = { 'name' : 'name', 'rate' : 'rate', 'geom' : 'MULTIPOLYGON', } lake_shp = './data/lakes.shp')) def run(verbose=True): lm = LayerMapping(Lakes, lake_shp, lakes_mapping, transform=False, encoding='iso-8859-1') lm.save(strict=True, verbose=verbose)
  39. 39. ogrinspect >>> python manage.py ogrinspect land/data/lakes.shp Lakes --mapping -- multi × --mapping indica a ogrinspect que genere el diccionario de mapeo para el LayerMapping. × --multi habilita la opción de usar MultiPolygonField en lugar de PolygonField
  40. 40. ogrinspect # This is an auto-generated Django model module created by ogrinspect. import os from django.contrib.gis.utils import LayerMapping from land.models import Lakes # Auto-generated `LayerMapping` dictionary for Lakes model lakes_mapping = { 'name' : 'name', 'rate' : 'rate', 'geom' : 'MULTIPOLYGON', }
  41. 41. Administrador de Django from django.contrib.gis import admin from models import Lakes admin.site.register(Lakes, admin.GeoModelAdmin) × admin.py
  42. 42. Ejemplo Obtener países con área similar
  43. 43. ¡Gracias! ¡En StyleSage estamos contratando! alicia@stylesage.co

Editor's Notes

  • https://es.wikipedia.org/wiki/John_Snow#El_mapa_del_c.C3.B3lera_de_John_Snow
    http://www.proyectosalonhogar.com/el_porque_de_las_cosas/historia_de_los_mapas.htm
  • https://es.wikipedia.org/wiki/John_Snow#El_mapa_del_c.C3.B3lera_de_John_Snow
    http://www.proyectosalonhogar.com/el_porque_de_las_cosas/historia_de_los_mapas.htm
  • PointField
    LineStringField
    PolygonField
    MultiPointField
    MultiLineStringField
    MultiPolygonField
    GeometryCollectionField
  • https://en.wikipedia.org/wiki/GIS_file_formats
    Raster formats[edit]
    ADRG – National Geospatial-Intelligence Agency (NGA)'s ARC Digitized Raster Graphics[2]
    Binary file – An unformatted file consisting of raster data written in one of several data types, where multiple band are stored in BSQ (band sequential), BIP (band interleaved by pixel) or BIL (band interleaved by line). Georeferencing and other metadata are stored one or more sidecar files.[3]
    Digital raster graphic (DRG) – digital scan of a paper USGS topographic map
    ECRG – National Geospatial-Intelligence Agency (NGA)'s Enhanced Compressed ARC Raster Graphics (Better resolution than CADRG and no color loss)
    ECW – Enhanced Compressed Wavelet (from ERDAS). A compressed wavelet format, often lossy.
    Esri grid – proprietary binary and metadataless ASCII raster formats used by Esri
    GeoTIFF – TIFF variant enriched with GIS relevant metadata
    IMG – ERDAS IMAGINE image file format
    JPEG2000 – Open-source raster format. A compressed format, allows both lossy and lossless compression.
    MrSID – Multi-Resolution Seamless Image Database (by Lizardtech). A compressed wavelet format, allows both lossy and lossless compression.
    netCDF-CF – netCDF file format with CF medata conventions for earth science data. Binary storage in open format with optional compression. Allows for direct web-access of subsets/aggregations of maps through OPeNDAP protocol.
    RPF – Raster Product Format, military file format specified in MIL-STD-2411[4]
    CADRG – Compressed ADRG, developed by NGA, nominal compression of 55:1 over ADRG (type of Raster Product Format)
    CIB – Controlled Image Base, developed by NGA (type of Raster Product Format)
    Vector formats[edit]
    See also: Comparison of Vector Formats (GIS)
    AutoCAD DXF – contour elevation plots in AutoCAD DXF format (by Autodesk)
    Cartesian coordinate system (XYZ) – simple point cloud
    Digital line graph (DLG) – a USGS format for vector data
    Esri TIN - proprietary binary format for triangulated irregular network data used by Esri
    Geography Markup Language (GML) – XML based open standard (by OpenGIS) for GIS data exchange
    GeoJSON – a lightweight format based on JSON, used by many open source GIS packages
    GeoMedia – Intergraph's Microsoft Access based format for spatial vector storage
    ISFC – Intergraph's MicroStation based CAD solution attaching vector elements to a relational Microsoft Access database
    Keyhole Markup Language (KML) – XML based open standard (by OpenGIS) for GIS data exchange
    MapInfo TAB format – MapInfo's vector data format using TAB, DAT, ID and MAP files
    National Transfer Format (NTF) – National Transfer Format (mostly used by the UK Ordnance Survey)
    Spatialite – is a spatial extension to SQLite, providing vector geodatabase functionality. It is similar to PostGIS, Oracle Spatial, and SQL Server with spatial extensions
    Shapefile – a popular vector data GIS format, developed by Esri
    Simple Features – Open Geospatial Consortium specification for vector data
    SOSI – a spatial data format used for all public exchange of spatial data in Norway
    Spatial Data File – Autodesk's high-performance geodatabase format, native to MapGuide
    TIGER – Topologically Integrated Geographic Encoding and Referencing
    Vector Product Format (VPF) – National Geospatial-Intelligence Agency (NGA)'s format of vectored data for large geographic databases
    Grid formats (for elevation)[edit]
    USGS DEM – The USGS' Digital Elevation Model
    GTOPO30 – Large complete Earth elevation model at 30 arc seconds, delivered in the USGS DEM format
    DTED – National Geospatial-Intelligence Agency (NGA)'s Digital Terrain Elevation Data, the military standard for elevation data
    GeoTIFF – TIFF variant enriched with GIS relevant metadata
    SDTS – The USGS' successor to DEM
    Other formats[edit]
    Dual Independent Map Encoding (DIME) – A historic GIS file format, developed in the 1960s
    Geographic Data Files (GDF) — An interchange file format for geographic data
    GeoPackage (GPKG) – An standards-based open format based on the SQLite database format for both vector and raster data
    Well-known text (WKT) – A text markup language for representing feature geometry, developed by Open Geospatial Consortium
    Well-known binary (WKB) – Binary version of Well-known text
    World file – Georeferencing a raster image file (e.g. JPEG, BMP)
  • https://2012books.lardbucket.org/books/geographic-information-system-basics/s06-02-map-scale-coordinate-systems-a.html
  • https://www.slideshare.net/arunvr/django-beyond-basics
  • http://www.paolocorti.net/2009/04/01/a-day-with-geodjango/
    GEOS (Geometry Engine Open Source)
    GDAL (Geospatial Data Abstraction Library)
    PROJ.4 (Cartographic Projections library)
    GeoIP C API
  • http://www.paolocorti.net/2009/04/01/a-day-with-geodjango/
    GEOS (Geometry Engine Open Source)
    GDAL (Geospatial Data Abstraction Library)
    PROJ.4 (Cartographic Projections library)
    GeoIP C API
  • http://www.paolocorti.net/2009/04/01/a-day-with-geodjango/
    Simplified Wrapper and Interface Generator
  • http://www.paolocorti.net/2009/04/01/a-day-with-geodjango/
    GEOS (Geometry Engine Open Source)
    GDAL (Geospatial Data Abstraction Library)
    PROJ.4 (Cartographic Projections library)
    GeoIP C API
  • http://www.paolocorti.net/2009/04/01/a-day-with-geodjango/
    GEOS (Geometry Engine Open Source)
    GDAL (Geospatial Data Abstraction Library)
    PROJ.4 (Cartographic Projections library)
    GeoIP C API
  • Well-known text (WKT) is a text markup language for representing vector geometry objects on a map, spatial reference systems of spatial objects and transformations between spatial reference systems. A binary equivalent, known as well-known binary (WKB), is used to transfer and store the same information on databases.
    The formats were originally defined by the Open Geospatial Consortium (OGC) and described in their Simple Feature Access and Coordinate Transformation Service specifications. The current standard definition is in the ISO/IEC 13249-3:2016 standard, "Information technology – Database languages – SQL multimedia and application packages – Part 3: Spatial" (SQL/MM) and ISO 19162:2015, "Geographic information – Well-known text representation of coordinate reference systems".
  • Well-known text (WKT) is a text markup language for representing vector geometry objects on a map, spatial reference systems of spatial objects and transformations between spatial reference systems. A binary equivalent, known as well-known binary (WKB), is used to transfer and store the same information on databases.
    The formats were originally defined by the Open Geospatial Consortium (OGC) and described in their Simple Feature Access and Coordinate Transformation Service specifications. The current standard definition is in the ISO/IEC 13249-3:2016 standard, "Information technology – Database languages – SQL multimedia and application packages – Part 3: Spatial" (SQL/MM) and ISO 19162:2015, "Geographic information – Well-known text representation of coordinate reference systems".
  • http://www.paolocorti.net/2009/04/01/a-day-with-geodjango/
    GEOS (Geometry Engine Open Source)
    GDAL (Geospatial Data Abstraction Library)
    PROJ.4 (Cartographic Projections library)
    GeoIP C API
  • Well-known text (WKT) is a text markup language for representing vector geometry objects on a map, spatial reference systems of spatial objects and transformations between spatial reference systems. A binary equivalent, known as well-known binary (WKB), is used to transfer and store the same information on databases.
    The formats were originally defined by the Open Geospatial Consortium (OGC) and described in their Simple Feature Access and Coordinate Transformation Service specifications. The current standard definition is in the ISO/IEC 13249-3:2016 standard, "Information technology – Database languages – SQL multimedia and application packages – Part 3: Spatial" (SQL/MM) and ISO 19162:2015, "Geographic information – Well-known text representation of coordinate reference systems".
  • Well-known text (WKT) is a text markup language for representing vector geometry objects on a map, spatial reference systems of spatial objects and transformations between spatial reference systems. A binary equivalent, known as well-known binary (WKB), is used to transfer and store the same information on databases.
    The formats were originally defined by the Open Geospatial Consortium (OGC) and described in their Simple Feature Access and Coordinate Transformation Service specifications. The current standard definition is in the ISO/IEC 13249-3:2016 standard, "Information technology – Database languages – SQL multimedia and application packages – Part 3: Spatial" (SQL/MM) and ISO 19162:2015, "Geographic information – Well-known text representation of coordinate reference systems".
  • http://www.paolocorti.net/2009/04/01/a-day-with-geodjango/
    GEOS (Geometry Engine Open Source)
    GDAL (Geospatial Data Abstraction Library)
    PROJ.4 (Cartographic Projections library)
    GeoIP C API
  • Well-known text (WKT) is a text markup language for representing vector geometry objects on a map, spatial reference systems of spatial objects and transformations between spatial reference systems. A binary equivalent, known as well-known binary (WKB), is used to transfer and store the same information on databases.
    The formats were originally defined by the Open Geospatial Consortium (OGC) and described in their Simple Feature Access and Coordinate Transformation Service specifications. The current standard definition is in the ISO/IEC 13249-3:2016 standard, "Information technology – Database languages – SQL multimedia and application packages – Part 3: Spatial" (SQL/MM) and ISO 19162:2015, "Geographic information – Well-known text representation of coordinate reference systems".
  • http://www.paolocorti.net/2009/04/01/a-day-with-geodjango/

×