Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Gentle Introduction to GIS (PyCon 2012)

A Gentle Introduction to GIS (PyCon 2012)

I gave a talk at PyCon! These are the slides! Hello!

Jason Scheirer

March 09, 2012
Tweet

Other Decks in Programming

Transcript

  1. Front Matter Things I wish I’d known Lots of theory

    The web is already covered bit.ly/pycongis
  2. Vector Data FILE Shapefile KML GML GPX GeoJSON Spatialite File

    GDB (Esri) DATABASE SQL Server Oracle PostGIS
  3. Raster Data FILE GeoTIFF JPEG2000 Esri GRID NetCDF HDF5 IMG

    ECW MrSID File GDB (Esri) DATABASE SQL Server Oracle PostGIS
  4. Mathematical model of planet/area of interest Datum/Grid/Benchmark Context for referring

    to places on model Geographic Coordinate System Mapping from geographic to map coordinates Projected Coordinate System Map
  5. >>> geod = pyproj.Geod(ellps='WGS84') >>> geod.npts(-116.993, 36.404, -0.659, 53.501, 10)

    [(-111.95067424159357, 41.97895680147041), (-105.96857250647616, 47.28567205186159), (-98.70968905555657, 52.20795019303087), (-89.76321873473009, 56.57373830261407), (-78.73417693105489, 60.137140502912196), (-65.50792704328728, 62.583294153845756), (-50.664741106486275, 63.59986753968315), (-35.59231296246254, 63.024821865584016), (-21.813955926298505, 60.952490703845044), (-10.156489980662073, 57.66944410754948)]
  6. >>> sr = arcpy.SpatialReference("WGS 1984 World Mercator") >>> start, end

    = (arcpy.Point(-116.993, 36.404), arcpy.Point(-0.659, 53.501)) >>> polyline = arcpy.Polyline(arcpy.Array([start, end]), sr) >>> [polyline.positionAlongLine(polyline.length * (idx / (11.))) for idx in xrange(12)] [<PointGeometry object at 0x2cca5e10[0x45ff6fe0]>, <PointGeometry object at 0x2cca5e90[0x2cca55e0]>, <PointGeometry object at 0x2cca5f10[0x2cca5da0]>, <PointGeometry object at 0x2cca5f30[0x2cca5ec0]>, <PointGeometry object at 0x2cca5f50[0x2cca5f60]>, <PointGeometry object at 0x2cca5f90[0x2cca5fa0]>, <PointGeometry object at 0x2cca5fd0[0x2cca5fe0]>, <PointGeometry object at 0x2cca5a90[0x2cca5ac0]>, <PointGeometry object at 0x2cca5610[0x2cca5a40]>, <PointGeometry object at 0x2cca5b90[0x2cca5b00]>, <PointGeometry object at 0x2cca40b0[0x2cca40c0]>, <PointGeometry object at 0x2cca40f0[0x2cca4100]>]
  7. Relational operators Contains Indicates if this geometry contains the other

    geometry. Crosses Indicates if the two geometries intersect in a geometry of lesser dimension. Disjoint Indicates if the two geometries share no points in common. Negate this result to compute the Intersect relation. Equals Indicates if the two geometries are of the same type and define the same set of points in the plane. Overlaps Indicates if the intersection of the two geometries has the same dimension as one of the input geometries. Touches Indicates if the boundaries of the geometries intersect. Within Indicates if this geometry is contained (is within) another geometry.
  8. Topological operators Boundary The boundary of this geometry. A polygon's

    boundary is a polyline. A polyline's boundary is a multipoint. A point or multipoint's boundary is an empty point or multipoint. Buffer Constructs a polygon that is the locus of points at a distance less than or equal to a specified distance from this geometry. Convex Hull Constructs the convex hull of this geometry. Cut Splits this geometry into a part left of the cutting polyline, and a part right of it. Difference Constructs the geometry containing points from this geometry but not the other geometry. Intersect Constructs the geometry that is the set-theoretic intersection of the input geometries. Use different resultDimension values to generate results of different dimensions. Symmetric Difference Constructs the geometry that contains points from either but not both input geometries. Union Constructs the geometry that is the set-theoretic union of the input geometries.
  9. Intersect/not disjoint (ArcGIS) sr = arcpy.SpatialReference("WGS 1984 World Mercator") with

    arcpy.da.SearchCursor('fastfood.shp', 'SHAPE@' spatial_reference=sr) as cursor: buffered_points = [row[0].buffer(1000) for row in cursor] with arcpy.da.SearchCursor('schools.shp', ['SHAPE@', 'school_name']) as school_cursor: schools_within_1k_of_fast_food = [row[1] for row in school_cursor if any(not shape.disjoint(pt) for pt in buffered_points)] buffer_dataset = arcpy.analysis.Buffer('fastfood.shp', r'in_memory\buffered_points', '1 kilometer') arcpy.analysis.SelectByLocation('schools.shp', 'within', buffer_dataset) arcpy.management.CopyFeatures('schools.shp', 'found_schools.shp') arcpy.management.Delete(buffer_dataset)