GEOTOOLS - Stata module to export data for GIS systems

Description

GEOTOOLS facilitates data export to shapefiles and GeoJSON files. It works fully within Stata (and hence works on any platform where Stata can be run) and does not have any dependencies (does not require e.g. ESRI ArcGIS or QGIS to be installed).

GEOTOOLS provides interactive dialogs, which can be of an advantage for novice users, and also can be called from the users' do and ado-files for massive or repetitive jobs.

The GEOTOOLS package contains additional utils for transforming the coordinates in Stata to bring them to the 'geography' format as required for the exporter to work.

Installation

To install geotools type literally the following in Stata's command prompt:

net from http://www.radyakin.org/stata/geotools/beta

Then click on the link for -geotools- in the Stata's viewer and click the -install- link.

Usage

Export in shapefile format

To export a file in shapefile format type the following in Stata's command line:

shapefile save geovar using "filename", type(shapefiletype)

For example:

clear

input str100 building str100 name
"-77.043346,38.899505;-77.041817,38.899505;-77.041817,38.898399;-77.043346,38.898399" "World Bank"
"-77.043657,38.898460;-77.044757,38.898460;-77.044757,38.899468;-77.043657,38.899468" "International Monetary Fund"
end

shapefile save building using "C:\TEMP\NGOs", type(polygon)

Do not specify any file extension as multiple files will be created. Specify option replace if you want existing files to be replaced.

The type of the shapefile determines the type of the features that are stored in it and can be one of the following: point, multipoint, polyline, polygon.

Shapefiles (of either type) do not have any styling options.

Export in GeoJSON format

To export a file in GeoJSON format type the following in Stata's command line:

geojson save geovar using "filename", features("Polygon")

For example:

clear

input str100 building str100 name
"-77.043346,38.899505;-77.041817,38.899505;-77.041817,38.898399;-77.043346,38.898399" "World Bank"
"-77.043657,38.898460;-77.044757,38.898460;-77.044757,38.899468;-77.043657,38.899468" "International Monetary Fund"
end

geojson save building using "C:\TEMP\NGOs.geojson", features("Polygon")

Standard file extension is .geojson or .json, most tools do not require extension to be present in the file, but it is a convention to specify it. Specify option replace if you want existing files to be replaced.

The option features determines the type of the features being added to the output file and must be one of the following exact words: Point, MultiPoint, LineString, or Polygon.

The writer to GeoJSON format will save all the notes associated with the data in memory. It also saves all other variables (besides the geography) into the same file.

The following attributes can be utilized during writing to GeoJSON files:

  • mcolor() - color of the markers in hex notation, e.g. #ff0000 for pure red;
  • msize() - size of the markers, one of the following: small, medium, large;
  • msymbol() - symbol to be used for the markers, which is a letter a..z, or a digit 0..9, or one of the symbols listed below;
  • scolor() - color of lines in hex notation, e.g. #00ff00 for pure green;
  • swidth() - width of lines (higher values = thicker lines);
  • sopacity() - opacity of the lines 0..1; 0=transparent, 1=opaque;
  • fcolor() - fill color in hex notation, e.g. #0000ff for pure blue;
  • fopacity() - opacity of polygons' fill; 0=transparent, 1=opaque.

symbols list

Here is the full list of symbols that can be used for markers

aerialway
airfield
airport
alcohol-shop
america-football
art-gallery
bakery
bank
bar
baseball
basketball
beer
bicycle
building
bus
cafe
camera
campsite
car
cemetery
chemist
cinema
circle-stroked
circle
city
clothing-store
college
commercial
cricket
cross
dam
danger
dentist
disability
dog-park
embassy
emergency-telephone
entrance
farm
fast-food
ferry
fire-station
fuel
garden
gift
golf
grocery
hairdresser
harbor
heart
heliport
hospital
ice-cream
industrial
land-use
laundry
library
lighthouse
lodging
logging
london-underground
marker-stroked
marker
minefield
mobilephone
monument
museum
music
oil-well
park2
park
parking-garage
parking
pharmacy
pitch
place-of-worship
playground
police
polling-place
post
prison
rail-above
rail-light
rail-metro
rail-underground
rail
religious-christian
religious-jewish
religious-muslim
restaurant
roadblock
rocket
school
scooter
shop
skiing
slaughterhouse
soccer
square-stroked
square
star-stroked
star
suitcase
swimming
telephone
tennis
theatre
toilets
town-hall
town
triangle-stroked
triangle
village
warehouse
waste-basket
water
wetland
zoo

Each of these options may include either a constant or a variable name. In the former case the same value will be applied for the corresponding attribute of each feature being written, in the latter, different features may have different values of the same attribute. E.g. to create a simple choropleth map, specify fcolor(colorvar), where colorvar is a string variable with the desired color of each polygon feature.

Note that some options are different in the dialog and command line! In the dialog opacity is specified in percent, and hence can have values 0..100, while in the command line you should specify values from the range 0..1.

Important

A particular GIS system may or may not follow the recommended attributes. They should be meant as recommendations only. Additional instructions may be required to make the GIS system reflect the data accordingly.

A GIS visualizer may decide to visualize other attributes then listed above. For example, if you had a variable named title or name some visualizers may recognize it as a feature name and display on the map as a feature label.

Live maps

GeoJSON files constructed with these commands can serve as the basis for the live maps online. See the following examples (based on artificial data around Fortaleza, Brazil location):

Author

GEOTOOLS was written by Sergiy Radyakin.

To contact the author send email to: sradyakin/at/worldbank.org.

Presentation from Stata Conference, Vancouver 2018-07-27