OpenMap is open source software written in Java which deals with geographic data. It provides plenty of examples but finding exactly what you need can sometimes be difficult.
OpenMap version: 4.6.5
ESRI Shape File version: TIGER2009
There are two parts to reading road data – there’s reading the “shape” data (i.e. lines), and reading whether a particular line represents a road or represents something else. Lines can be read using ShapeFile.java as shown below. Whether or not a particular record is a road or not, is represented by the road flag, aka “ROADFLG.” The ROADFLG can be read using … as shown below.
Method: public static void main(String args)
Usage: Pass in the full path to the .shp file as the first and only argument. The data type ESRIRecord holds the lat/long data.
bounds: Two lat/long points which describe the bounding box of the line(s).
polygons: holds various parts / polygons
radians: holds points used to plot the road/line data
In addition to the bounding box, there are a number of associated polygons (usually only one as far I can tell) with a number of “radians” associated with the polygon. These are coordinates inside the bounding box which are used to actually form the Polyline. The Polyline is simply a string of lines that when drawn end to end approximate the curve of the road (i.e. it is the road shape).
Thus, in order to read the shape of a road, you’ll have to get the bounding box, then plot the points within the box, where the points are the radians.
It turns out radians are a different format than the bounding box itself, which can make plotting them difficult. The conversion from “degrees” to “radians” is done by OpenMap automatically. To get the degrees you’ll have to drill down into the following classes and methods.
com.bbn.openmap.layer.shape.ESRIPolygonRecord (see variable “polygons” of type ESRIFloatPoly)
The decimal degrees are in the same format as the bounding box, that is, latitude and longitude. Once the points are available as lat/long points inside a lat/long bounding box, plotting the points requires converting from lat/long to x/y coordinates, and adjusting for the inherent “curve” of the measurement.
This is less strange.
Method: public static void main(String argv)
Usage: Pass in the full path to the .shp file as the first and only argument. The data type DbfTableModel will hold the ROADFLG once the file is read.
One of the columns will be named “ROADFLG” and the record number corresponds to the row number. So you can read whether a certain row has “Y” for the ROADFLG by using .getValueAt(row, col).