+ All Categories
Home > Documents > Tim Brophy Stata Conference July 18–19, 2013 New Orleans

Tim Brophy Stata Conference July 18–19, 2013 New Orleans

Date post: 13-Feb-2016
Category:
Upload: abra
View: 35 times
Download: 2 times
Share this document with a friend
Description:
gpsmap: Routine for verifying and returning the attributable table of given decimal GPS coordinates from a user provided Shapefile. Tim Brophy Stata Conference July 18–19, 2013 New Orleans. What is spatial data? How is it useful? Spatial Data Structure gpsmap Graphically Syntax Demo - PowerPoint PPT Presentation
42
gpsmap: Routine for verifying and returning the attributable table of given decimal GPS coordinates from a user provided Shapefile Tim Brophy Stata Conference July 18–19, 2013 New Orleans
Transcript
Page 1: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

gpsmap: Routine for verifying and returning the attributable table of given

decimal GPS coordinates from a user provided Shapefile

Tim BrophyStata Conference July 18–19, 2013

New Orleans

Page 2: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

Overview

• What is spatial data?• How is spatial data useful to researchers?• Spatial Data Structure• gpsmap introduction• gpsmap graphically• gpsmap syntax• gpsmap demonstration• gpsmap how it works• Acknowledgments

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

Page 3: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

What is spatial data?

• Geographic data – Latitude and longitude coordinates – Accompanying attribute data.

Page 4: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

What is spatial data?

• Identifies geographic locations, features and boundaries.

• Spatial data is often accessed, manipulated or analysed through Geographic Information Systems (GIS).

Page 5: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

How is spatial data useful to researchers?

• Allows researcher to analyse data within or across geographical locations.– In order for this to happen the locations

need to be known• Provides data regarding the given

geographical locations. Such as:– population density– geo type (i.e. urban or formal )

Page 6: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

Spatial Data Structure

Spatial data is normally stored in the ESRI Shapefile format.• Shapefiles data is a relational dataset

– Thus there are multiple tables connected by a primary key.

– Each of these table come as a separate file extension. – At a minimum there are three mandatory file

extensions.• .shp — shape format; the geometry itself.• .dbf — attribute format; columnar attributes for each shape• .shx — shape index format; a positional index of the feature

geometry

Page 7: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

.shp in more detail

.shp contains all the geo location data.

Page 8: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

.shp in more detail

.shp contains all the geo location data.

Index Y X

1 31.5867 -32.6729

Latitude Longitude

Page 9: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

.shp in more detail

.shp contains all the geo location data.

Index Y X

1 31.5867 -32.6729

1 31.8769 -33.8394

Latitude Longitude

Page 10: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

.shp in more detail

.shp contains all the geo location data.

Index Y X

1 31.5867 -32.6729

1 31.8769 -33.8394

1 31.1762 -31.8617

Latitude Longitude

Page 11: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

.shp in more detail

.shp contains all the geo location data.

Index Y X

1 31.5867 -32.6729

1 31.8769 -33.8394

1 31.1762 -31.8617

1 31.3846 -31.2675

Latitude Longitude

Page 12: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

.shp in more detail

.shp contains all the geo location data.

Index Y X

1 31.5867 -32.6729

1 31.8769 -33.8394

1 31.1762 -31.8617

1 31.3846 -31.2675

1 31.9825 -32.3578

Latitude Longitude

Page 13: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

.shp in more detail

.shp contains all the geo location data.

Index Y X

1 31.5867 -32.6729

1 31.8769 -33.8394

1 31.1762 -31.8617

1 31.3846 -31.2675

1 31.9825 -32.3578

1 31.6112 -32.3698

Latitude Longitude

Page 14: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

.shp in more detail

.shp contains all the geo location data.

Index Y X

1 31.5867 -32.6729

1 31.8769 -33.8394

1 31.1762 -31.8617

1 31.3846 -31.2675

1 31.9825 -32.3578

1 31.6112 -32.3698Polygon

Latitude Longitude

Page 15: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

.dbf in more detail

.dbf contains the attributes of the Shapefile. These are user defined attributes.

Attribute1 Attribute2 Index

Province Country 1

Page 16: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

.dbf in more detail

.dbf records merge to .shp file with a one to many relationship.

Attribute1 Attribute2 Index

Province Country 1

Index Y X1 31.5867 -32.67291 31.8769 -33.83941 31.1762 -31.86171 31.3846 -31.26751 31.9825 -32.35781 31.6112 -32.3698

Page 17: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

gpsmap: Introduction

gpsmap; a user written Stata command to map a gps coordinates onto a Shapefile. It produces two main outputs:Output 1Binary variable indicating whether the GPS coordinates were mapped to the .shpOutput 2Where the coordinates were mapped, gpsmap returns the attribute table from the .dbf file.

Page 18: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

OUTSIDE INSIDE

Valid = 0 Valid = 1

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

gpsmap: Explained graphically

Map GPS coordinates: (Latitude 31.58769, Longitude -32.34962)

Output 1:Determine if the given GPS coordinates fall within the bounds of the polygon

Page 19: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

gpsmap: Explained graphically

Map GPS coordinates: (Latitude 31.58769, Longitude -32.34962)

Output 2:Where points map to polygon attribute table is returned.

Attribute1 Attribute2 Index

Province Country 1

Page 20: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

gpsmap: Syntax

Syntax gpsmap using shapefilename [if] , latitude(variable) longitude(variable) [options]

Options valid(newvar) prefix(string) keepusing(varlist)

Page 21: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

gpsmap: Demonstration

Input: Shapefile of South Africa’s boundary

Page 22: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

gpsmap: Demonstration

Input: GPS coordinates

ID Latitude Longitude Expected valid

1 -27.776030° 18.552530° 0

Page 23: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

gpsmap: Demonstration

Input: GPS coordinates

ID Latitude Longitude Expected valid

1 -27.776030° 18.552530° 0

2 -30.682771° 22.600851° 1

Page 24: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

gpsmap: Demonstration

Input: GPS coordinates

ID Latitude Longitude Expected valid

1 -27.776030° 18.552530° 0

2 -30.682771° 22.600851° 1

3 -29.715901° 27.930595° 0

Page 25: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

gpsmap: Demonstration

Input: GPS coordinates

ID Latitude Longitude Expected valid

1 -27.776030° 18.552530° 0

2 -30.682771° 22.600851° 1

3 -29.715901° 27.930595° 0

4 -24.407324° 29.751723° 1

Page 26: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

gpsmap: Demonstration

Input: GPS coordinates

ID Latitude Longitude Expected valid

1 -27.776030° 18.552530° 0

2 -30.682771° 22.600851° 1

3 -29.715901° 27.930595° 0

4 -24.407324° 29.751723° 1

5 -30.429434° 29.463932° 1

Page 27: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

gpsmap: Demonstration

gpsmap using “C:\Users\Tim\Desktop\geo_coding\SOU_outline_SHP\SOU_outline.shp”, latitude(Latitude) longitude(Longitude) valid(demo_valid)

Page 28: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

gpsmap: Demonstration

gpsmap using “C:\Users\Tim\Desktop\geo_coding\SOU_outline_SHP\SOU_outline.shp”, latitude(Latitude) longitude(Longitude) valid(demo_valid)

Run time 0.11 seconds

Page 29: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

gpsmap: Demonstration

gpsmap using “C:\Users\Tim\Desktop\geo_coding\SOU_outline_SHP\SOU_outline.shp”, latitude(Latitude) longitude(Longitude) valid(demo_valid)

Run time 0.11 seconds

Page 30: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

gpsmap: Demonstration

gpsmap using “C:\Users\Tim\Desktop\geo_coding\SOU_outline_SHP\SOU_outline.shp”, latitude(Latitude) longitude(Longitude) valid(demo_valid)

Run time 0.11 seconds

Page 31: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

gpsmap: How it works

Gpsmap is made up of four main sub-routines

• .dbf reader• .shp header reader• .shp polygon reader• Point in polygon ray casting routine

Page 32: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

.dbf reader

The .dbf reader reads the attribute table into Stata.

• Controls for length of variable names 32 characters or less.

• Imports all data as string format into Stata and then gets Stata to convert to numeric where applicable.

• Due to this all variables are limited to 244 characters long.

Page 33: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

.shp header reader

The .shp reader reads the polygon headers into Mata.Each polygon shape has a header record in the Shapefile, the record contains:

• The polygon number in the shape file, i.e. record number.

• The bounding box– Min X, Max X, Min Y, Min Y

• The start position of the polygon shape in the Shapefile.

Page 34: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

.shp polygon reader

The .shp polygon reader reads a specific polygon from the Shapefile into Mata

Each GPS point from Stata is compared with the Max and Min values in the polygon header tables, selecting the most likely polygon that it will fall into.

Each selected polygon is then read in using the polygon reader.

Done for both performance and memory efficiency.

Page 35: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

Point in polygon routine

So far:• Polygon headers have been read in.• Most likely polygon have been identified and

read in.• Now determine which polygon out of the

likely polygon the GPS point falls into.

Page 36: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

Point in polygon routine

A ray casting routine is used making use of the odd even rule.Rule states: If a point lies within a polygon then the a ray cast from that point to infinity, will intersect the border of the polygon an odd number of times if it lies within the polygon.

Page 37: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

Point in polygon routine

A ray casting routine is used making use of the odd even rule.Rule states: If a point lies within a polygon then the a ray cast from that point to infinity, will intersect the border of the polygon an odd number of times if it lies within the polygon.

Page 38: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

Point in polygon routine

A ray casting routine is used making use of the odd even rule.Rule states: If a point lies within a polygon then the a ray cast from that point to infinity, will intersect the border of the polygon an odd number of times if it lies within the polygon.

Page 39: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

Point in polygon routine

A ray casting routine is used making use of the odd even rule.Rule states: If a point lies within a polygon then the a ray cast from that point to infinity, will intersect the border of the polygon an odd number of times if it lies within the polygon.

1Odd # intersections

∴ inside

Page 40: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

Point in polygon routine

A ray casting routine is used making use of the odd even rule.Rule states: If a point lies within a polygon then the a ray cast from that point to infinity, will intersect the border of the polygon an odd number of times if it lies within the polygon.

1Even # intersections

∴ Outside2

Page 41: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

Point in polygon routine

Calculating the intersections.• Calculated the X coordinate of the

intersection given Y.– Between a horizontal ray cast from point of

interest and the borders of the polygon.– Count number of determined X results that are

greater than or equal to the X value for the point of interest.

– If count is Odd then inside, if count is even then outside

Page 42: Tim Brophy Stata Conference July 18–19, 2013  New Orleans

What is spatial data?How is it useful?Spatial Data StructuregpsmapGraphicallySyntaxDemoHow it worksAcknowled -gments

Acknowledgments and thanks

Kevin Crow • shp2dta

Reza C. Daniels and Sibongile Musundwa• Co-authors and testing

Louise De Villiers, Michelle Chinhema and the rest of the NIDS team. • Support utilization and testing gpsmap.

• Email: [email protected] • Nids: http://www.nids.uct.ac.za


Recommended