DATA2001 · Data Science, Big Data and Data Variety
Geospatial Data
Week 8 works with (geo-)spatial data: spatial types (point, line, polygon), bounding boxes, and querying points of interest within a region, using PostgreSQL/PostGIS with SRID 4326 (WGS84 longitude/latitude). It is grounded in the ABS Statistical-Area hierarchy (SA2 within SA4) that the 20% group assignment loops over to collect POIs, and spatial querying is directly examined in the 50% final.
What this chapter covers
- 01Spatial vs geospatial data; why 'where' adds meaning; spatial queries (within-radius, within-region)
- 02Vector data (point 0-D, line 1-D, polygon 2-D, plus Multi* collections) vs raster data (a grid of cells)
- 03Coordinate systems: Cartesian, geodetic longitude/latitude, projected; SRID 4326 = WGS84 in degrees (X = lon, Y = lat)
- 04PostGIS: CREATE EXTENSION postgis; geometry(Point, 4326); ST_Point(lon, lat), ST_AsText, ST_X/ST_Y, ST_AsGeoJSON; GiST index
- 05Geometry (Cartesian plane, fast) vs Geography (earth surface, accurate) and the ::geography cast for metre distances
- 06Topological relations (touches, contains vs covers, within, disjoint, overlaps) and the filter-refine strategy with an MBR
- 07Bounding-box POI query and the SA4-to-SA2 region hierarchy used by the assignment
Building a bounding box around a point of interest
- +1Compute the half-width delta. delta = boxsize ÷ (100 × 2) = 4 ÷ 200 = 0.02 degrees. This is how far the box extends from the centre in each direction (in degrees, on the WGS84 lon/lat grid).
- +1Offset longitude (X). xmin = 150.90 - 0.02 = 150.88; xmax = 150.90 + 0.02 = 150.92.
- +1Offset latitude (Y). ymin = -33.75 - 0.02 = -33.77; ymax = -33.75 + 0.02 = -33.73. The envelope (xmin, ymin, xmax, ymax) = (150.88, -33.77, 150.92, -33.73) is passed to the API to return POIs inside it.
- +1The ::geography cast. Coordinates are in degrees, so a raw geometry distance is measured in degrees, not metres. Casting geometry to ::geography (e.g. ST_Distance(a::geography, b::geography) or ST_DWithin(..., 100)) makes PostGIS return distances in metres on the earth's surface — without it, a '100' threshold means 100 degrees, which is meaningless.
Key terms
- Vector vs raster data
- Vector data represents features as shapes — points (0-D, e.g. a school), lines (1-D, e.g. a river) and polygons (2-D, e.g. a suburb), with Multi* collections. Raster data is a matrix of cells (pixels), each holding a value, as in a satellite image or elevation grid.
- SRID 4326 (WGS84)
- The standard geographic coordinate reference system used in the unit: longitude (X) and latitude (Y) in degrees. GeoJSON always uses lon, lat in this CRS, and PostGIS columns are declared geometry(Point, 4326).
- PostGIS
- PostgreSQL's spatial extension (CREATE EXTENSION postgis). It adds geometry/geography types and functions such as ST_Point, ST_AsText, ST_X/ST_Y, ST_AsGeoJSON, ST_Distance and ST_DWithin, indexed with GiST.
- Geometry vs Geography
- The geometry type assumes coordinates lie on a flat Cartesian plane (fast, degree-based); the geography type assumes points on the earth's surface (lat/lon), giving accurate metre distances at higher CPU cost. Cast on demand with ::geometry or ::geography.
- Minimum Bounding Rectangle (MBR) and filter-refine
- The MBR is the smallest axis-aligned rectangle enclosing a geometry. Spatial queries filter cheaply by MBR overlap, then refine by testing the true geometry only for the surviving candidates.
- Contains vs covers
- Two topological relations: in covers, the boundaries may touch (the boundary intersection is non-empty); in contains, one shape lies strictly inside the other's interior with boundaries not meeting. The mirror pair is within vs coveredBy.
Geospatial Data FAQ
What is the difference between the geometry and geography types?
geometry treats coordinates as points on a flat Cartesian plane, which is fast and fine over small areas but measures distances in the coordinate unit (degrees for SRID 4326). geography treats them as points on the earth's ellipsoid, so area, distance and length come out accurately in metres over large scales, at more CPU cost and with fewer functions defined. You commonly store geometry and cast to ::geography when you need metre-accurate distances.
Why do my PostGIS distances come out in degrees instead of metres?
Because your coordinates are in SRID 4326 (degrees) and you called a distance function on the raw geometry. ST_Distance and ST_DWithin measure in the geometry's own units, so a threshold like 100 means 100 degrees. Cast both operands to ::geography — ST_DWithin(a::geography, b::geography, 100) — and the 100 is interpreted as 100 metres. This degrees-vs-metres cast is the unit's signature spatial gotcha.
What is the filter-refine strategy and why use it?
Exact geometry tests (does this irregular polygon intersect that one?) are expensive, so PostGIS first approximates each object by its Minimum Bounding Rectangle and cheaply keeps only those whose MBR overlaps the query region (filter), then runs the exact geometry test on the few survivors (refine). It is the same idea behind bounding-box POI queries and R-tree/GiST spatial indexes.
Can AI help me with spatial SQL and PostGIS in DATA2001?
Yes. Sia can explain SRID 4326, walk through building a bounding box, writing ST_DWithin/ST_Distance with the right ::geography cast, and reasoning about topological relations, and it will check your coordinates and signs. Practise on neutral coordinates. It supports your study and does not do the graded group assignment for you; the University of Sydney academic-integrity policy applies.
Exam move
Spatial data is heavily used in the group assignment, so make the core moves automatic. Fix the coordinate convention in your head — longitude is X, latitude is Y, southern latitudes negative, SRID 4326 in degrees — and practise building a bounding box around a centre point (delta offsets on each axis). Learn the PostGIS starter kit: CREATE EXTENSION postgis, a geometry(Point, 4326) column, ST_Point(lon, lat), reading back with ST_AsText/ST_X/ST_Y, a GiST index, and above all the ::geography cast for metre distances (the degrees-vs-metres trap is a guaranteed exam point). Be able to name the vector types, contrast geometry vs geography, and describe filter-refine with an MBR. Rehearse the SA4-to-SA2 loop idea behind the assignment's POI collection. Ask Sia to set fresh bounding-box and distance drills and check your casts; confirm assessment details on Canvas.
Working through Geospatial Data in DATA2001? Sia is AskSia’s AI Data Science tutor — ask any DATA2001 Geospatial Data question and get a clear, step-by-step explanation grounded in how DATA2001 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.