Monday, February 28, 2011

Doing a simple spatial selection with gvSIG

If you are used to running spatial selection queries in commercial GIS applications, then you would be a little confused to do the same thing in gvSIG. It took me a little while to figure out that gvSIG requires me to do pre-selection sets of the geometries for analysis first to reduce the amount of data before performing the actual spatial selection. To illustrate how to do a spatial selection query using the open source software gvSIG, I will do a simple point over polygon spatial overlay selection query.


  1. Start up gvSIG. Add the point and polygon layers for analysis into the View, e.g. Cities.shp and States.shp.

    The layers are displayed.

  2. In the legend, click the polygon layer e.g. States.shp to make it the active layer.

    The legend name is displayed in bold and enclosed in a box.
  3. On the toolbar, click the Select by Point icon. Click on a state polygon e.g. Arizona.

    The polygon is highlighted in yellow.

  4. In the legend, click the point layer e.g. Cities.shp to make it the active layer.

    The legend name is displayed in bold and enclosed in a box.
  5. On the toolbar, click the Select By Rectangle icon. Click and drag out a box covering the cities over Arizona and beyond.

    The points are highlighted in yellow.

  6. On the toolbar, click the Spatial Selection icon.



    The Spatial selection dialog box appears.

  7. In the Select features from active layers that field, choose are contained in.
  8. In the selected features in layer field, choose the polygon layer e.g. States.shp.


  9. Click New selection.

    Only the points that are contained in the Arizona state polygon are highlighted.
  10. Click Cancel.
  11. In the legend, toggle off the polygon layer e.g. States.shp to see the spatially selected points.

Monday, February 21, 2011

Example C# code to directly change existing LiDAR LAS file field values

For more efficient manipulation of LiDAR LAS files, C# can be used to directly change values in binary LAS files. Here is a simple example code snippet for locating and changing the Z bounding range fields of an existing LiDAR LAS file.

Essentially, the LAS file has to be opened as a binary file stream first. Then the file stream pointer has to be moved to the correct starting offset of a field before you can change the field values of the existing LAS file using the binary writer's write method. You have to ensure the C# data types match the LAS file fields though. In this case, the starting offsets for the Max Z and Min Z fields (doubles at 8 bytes each) are at  211 and 219 bytes respectively.

For more details about the LAS fields and the byte offsets, click on this link http://liblas.org/development/specifications.html.


double maxz, minz;
//....etc....
//Somewhere here the Z bounding range (minz and maxz) is calculated

//Open a file stream to the LAS file
FileStream fs = File.Open(@"C:\Temp\file.las", FileMode.Open);
if (fs.CanSeek)
{
    BinaryWriter binWriter = new BinaryWriter(fs);
    //move to the location of the maxz field in the LAS file
    fs.Seek(211, SeekOrigin.Begin); 
    //Write the maxz double value to the LAS file
    binWriter.Write(maxz);
    //move to the location of the minz field in the LAS file
    fs.Seek(219, SeekOrigin.Begin); 
    //Write the minz double value to the LAS file
    binWriter.Write(minz);
    //Close the writer
    binWriter.Close();
}
//Close the LAS file
fs.Close();
}

Monday, February 14, 2011

Removing holes from polygons with Global Mapper

Sometimes I want to remove the holes inside polygons. Global Mapper provides a convenient function to do the job. Here are the steps that I use:

  1. Start up Global Mapper. Load in a polygon with holes.

    The polygon is loaded.

  2. On the keyboard, press ALT+D to activate the Digitizer Tool.

    The cursor changes to a cross hair with the Edit label.
  3. Click on the polygon.

    The polygon is selected.

  4. Mouse right click anywhere inside the map window.

    A pop up menu appears.

  5. Choose Advanced Selection Options | Select Island Areas in Selected Area Feature.

    All the holes are selected.
  6. Mouse right click anywhere inside the map window.

    A pop up menu appears.

  7. Choose Delete Selected Features.

    The holes are deleted.

Monday, February 7, 2011

Rotate geometries in Global Mapper

Rotating graphics is a common task in CAD software. It took Intergraph a while to add in CAD like functionalities in GeoMedia Professional. In Global Mapper, it is quite simple to rotate feature geometries about a point. Simply do the following:
  1. Start up Global Mapper. Digitize one or more vector geometries or load up a vector file.

  2. Click the Digitizer Tool  icon.
  3. Select one or more feature with the mouse.

    The features are selected.
  4. Press the right button of the mouse anywhere inside the map window.

    A pop up menu appears.
  5. Choose Rotate/Scale Selected Feature(s).

    The Setup Rotation and Scaling dialog box appears.
  6. In the Rotation Angle (Clockwise) field, type in the angle of rotation, e.g. 90.
  7. There are a few options to define the point of rotation - center, specific location, or vertex. Choose a method, e.g. About Vertex.

    Note: Unfortunately, you are not able to graphically click on a position. The location must be typed in, or selected from a list. However, Global Mapper shows you a preview of the rotation point (a red colored cross), as shown below.

  8. Click OK.

    The selected features are rotated.