Showing posts with label intergraph. Show all posts
Showing posts with label intergraph. Show all posts

Monday, February 4, 2013

GeoMedia code snippet to apply a workspace spatial filter

In GeoMedia, a Spatial filter is a means to improve the application performance by reducing the amount of spatial data for display and processing. Typically, this is done using an arbitrary polygon as the spatial filter boundary.

The following C# code snippet can be used as a method in a driving GeoMedia type custom application to apply a rectangular spatial filter to the GeoMedia workspace.


using GMService = Intergraph.GeoMedia.GMService;
using PService = Intergraph.GeoMedia.PService;
using PBasic = Intergraph.GeoMedia.PBasic;
using PClient = Intergraph.GeoMedia.PClient;
 
//...etc....
private GeoMedia.Application _application = null;
//...etc...

public void ApplyWorkspaceSpatialFilter(PBasic.point lowerLeftPoint, PBasic.point upperRightPoint)
{
//Declare variables
PBasic.PolygonGeometry polygon;
PBasic.point pnt;
object objBlob;
PClient.GeometryStorageService storageSvc;
GMService.ApplySpatialFilterService spatFilterSvc;
 
//Create a new instance of the ApplySpatialFilterService
spatFilterSvc = new GMService.ApplySpatialFilterService(); 
 
//Create a new polygonGeometry object for the spatial filter polygon
polygon = (PBasic.PolygonGeometry) _application.CreateService("GeoMedia.PolygonGeometry");

//Create a new GeoMedia point object
pnt = (PBasic.point)_application.CreateService("GeoMedia.point");

//Populate the spatial filter polygon object with the bounding rectangle
pnt.X = lowerLeftPoint.X;
pnt.Y = lowerLeftPoint.Y;            
polygon.Points.Add ( pnt, null);
pnt.X = lowerLeftPoint.X;
pnt.Y = upperRightPoint.Y;
polygon.Points.Add (pnt, null);
pnt.X = upperRightPoint.X;
pnt.Y = upperRightPoint.Y;
polygon.Points.Add (pnt, null);
pnt.X = upperRightPoint.X;
pnt.Y = lowerLeftPoint.Y;
polygon.Points.Add (pnt, null);
pnt.X = lowerLeftPoint.X;
pnt.Y = lowerLeftPoint.Y;
polygon.Points.Add (pnt, null);
 
//Create a new instance of the GeometryStorageService object
storageSvc = (PClient.GeometryStorageService) _application.CreateService("GeoMedia.GeometryStorageService");

//Convert the polygonGeometry object into a blob
storageSvc.GeometryToStorage(polygon, out objBlob);
 
//Assign the polygonGeometry to the SpatialFilterService object and apply the spatial filtering to
//the GeoMedia application workspace
spatFilterSvc.Application = this._application;
spatFilterSvc.SpatialFilterOperator = PClient.GConstants.gdbTouches;
spatFilterSvc.SpatialFilterGeometry = objBlob;
spatFilterSvc.SpatialFilterName = "SpatialFilter1";
spatFilterSvc.UseGeometryMBR = false;
spatFilterSvc.Execute();
 
//Free up resources
objBlob = null;
if (spatFilterSvc != null) Marshal.FinalReleaseComObject(spatFilterSvc);
if (storageSvc != null) Marshal.FinalReleaseComObject(storageSvc);
if (polygon != null) Marshal.FinalReleaseComObject(polygon);
if (pnt != null) Marshal.FinalReleaseComObject(pnt);
}

Monday, November 19, 2012

GeoMedia C# code snippet to get the warehouse connection's table list

It is useful to programmatically retrieve the list of tables in a GeoMedia warehouse via the connection object. The GeoMedia MetadataService can be called upon to generate the list in a String array. The following C# code snippet shows how this can be done.

The connection object is passed in to the GetTableList method and returns an ArrayList of table names.

using GeoMedia = Intergraph.GeoMedia.GeoMedia;
using PCSS = Intergraph.GeoMedia.PCSS;
using PBasic = Intergraph.GeoMedia.PBasic;
using GDO = Intergraph.GeoMedia.GDO;
using PClient = Intergraph.GeoMedia.PClient;
using PService = Intergraph.GeoMedia.PService;
using GMService = Intergraph.GeoMedia.GMService;
//...etc...
private ArrayList GetTableList(PClient.Connection conn)
{
String[] list = null;
ArrayList tables = new ArrayList();
object oConn = (object)conn;
int mask = 0;
object vTables = null;
GMService.MetadataService metadataSvc = null;

//Create an instance of the GeoMedia MetadataService
metadataSvc = new GMService.MetadataService();
//Pass in the connection object to the MetadataService
metadataSvc.set_Connection(ref oConn);
//Get the connection's list of tables and put them into the vTables array
metadataSvc.GetTables(ref mask, ref vTables);

//copy the table list into an ArrayList and return to the calling function
list = (String [])vTables;
for (int i = 0; i < list.Length; i++)
tables.Add(list[i].ToUpper());
return tables;
}

Monday, July 30, 2012

Geomedia code to get the GRecordset's Connection object

When developing driving GeoMedia type applications, I find it convenient to be able to determine from which database connection a feature record set is from. The following C# code snippet is a private method that given a collection of Connection object and a GRecordset object, it returns the Connection object of the record set; or null if it could not find a match.


using PClient = Intergraph.GeoMedia.PClient;
//...etc...
private PClient.Connection GetRecordSetConnection(PClient.Connections conns, PClient.GRecordset rs)
{
PClient.GFields flds = null;
PClient.Connections conns = null;
PClient.GDatabase db = null;
PClient.Connection conn = null;
 
//Get the recordset's GFields collection object
flds = rs.GFields;
 
//Loop through the GeoMedia documents' list of connections
foreach (PClient.Connection cn in conns)
{
//Ignore closed connections
if (cn.Status != PClient.ConnectionConstants.gmcStatusClosed)
{
//Get the current connection's database object
db = (PClient.GDatabase) cn.Database;
//If the recordset's field database name matches the
//connection's database name, then we have found the right connection object
if (db.Name.Equals(flds[0].SourceDatabase))
{
conn = cn;
break;
}
}
}
//Free up memory used by the GeoMedia COM objects
if (flds != null) 
Marshal.FinalReleaseComObject(flds);
if (conns != null) 
Marshal.FinalReleaseComObject(conns);
if (db != null) 
Marshal.FinalReleaseComObject(db);

return conn;
}

Monday, May 7, 2012

How to detect changes between two GeoMedia polygon features

Detecting changes between two polygon vector features is a common workflow in GIS especially for forestry, and land use planning. For example, it may be useful to quantify the amount of forest cover changes (loss of vegetation, or vegetation growth) between two periods of time. GeoMedia provides the spatial analysis functions that can help to detect the changes provided the polygon vegetation features for the two periods of time are available. The example below illustrates how to use GeoMedia's Spatial Difference command to identify the loss of vegetation and vegetation growth.


Identify the loss of vegetation

  1. In GeoMedia, select Analysis | Spatial Difference.

    The Spatial Difference dialog box appears.

  2. In the From features in combo box, select the later vegetation polygon feature e.g. Vegetation2012.
  3. In the Subtract features in combo box, select the earlier vegetation polygon feature e.g. Vegetation2002.
  4. In the Output difference as Query name field, type in a meaningful string e.g. Loss of Vegetation since 2002.
  5. Optional. Click the Style button and set a thick border color e.g. red.
  6. Click OK.

    The areas representing the loss of vegetation since 2002 are displayed in red.

Identify the new vegetation growth
  1. Select Analysis | Spatial Difference.

    The Spatial Difference dialog box appears.

  2. In the From features in combo box, select the later vegetation polygon feature e.g. Vegetation2012.
  3. In the Subtract features in combo box, select the earlier vegetation polygon feature e.g. Vegetation2002.
  4. In the Output differences as Query name field, type in a meaningful string e.g. New vegetation growth since 2002.
  5. Optional. Click Style and set a thick green border color.
  6. Click OK.

    The new vegetation growth areas are displayed in dark green.
     

Monday, March 19, 2012

Use the GeoMedia Math Service to get the range of any geometry object

It is useful to be able to programmatically determine the coordinate ranges of any GeoMedia geometry object, e.g. polygon, point, line, etc. The example C# code snippet below is from part of a 'driving GeoMedia application' that illustrates how to get the geometry range coordinates.


// ...etc...
using GeoMedia = Intergraph.GeoMedia.GeoMedia;
using GeoMath = Intergraph.GeoMedia.GeoMathSvc;
using PBasic = Intergraph.GeoMedia.PBasic;
// ...etc...
 
// Create a new instance of the GeoMedia application framework
private GeoMedia.Application _application = (GeoMedia.Application)Activator.CreateInstance(GeoMediaType);
//...etc..
 
// pass in any geometry object as objGeom and read the min range from loRange and the max range from hiRange
public void GetAnyGeometryRange(object objGeom, out PBasic.point lowRange, out PBasic.point highRange)
{
GeoMath.GeoMathService geoMathSvc;    //the GeoMedia Math Service object
GeoMath.point lowerLeftPoint, upperRightPoint;    //the lower left and upper right GeoMedia point objects
 
//Use the GeoMedia application to create the GeoMedia point objects for storing the min and max range points
lowerLeftPoint = (GeoMath.point)_application.CreateService("GeoMedia.point");
upperRightPoint = (GeoMath.point)_application.CreateService("GeoMedia.point");
 
//Create the GeoMedia Math Service
geoMathSvc = (GeoMath.GeoMathService)_application.CreateService("GeoMedia.GeoMathService");

//Use the GeoMedia Math Service to calculate the geometry range
geoMathSvc.GetRange(objGeom, lowerLeftPoint, upperRightPoint);
 
//Store the range points for passing back the values to the calling function
lowRange = (PBasic.point) lowerLeftPoint;
highRange = (PBasic.point) upperRightPoint;
 
//finally free up the memory used by the GeoMedia Math Service COM object
if (geoMathSvc != null) 
Marshal.FinalReleaseComObject(geoMathSvc);
}

Monday, August 15, 2011

Finding the Intergraph Host ID string for license generation

In order to generate licenses for Intergraph GeoMedia products, a host id may be required as input to the license  generation process. Whenever GeoMedia could not obtain a valid license, it will pop up the screen shown below.



Previously, the Host ID field contains only a 12 characters hexadecimal string e.g. 08002711d817, which is the actual host id string that can be copied and use to generate the software license. But recently, Intergraph changed the string to include additional hexadecimal characters but still labelled the entire string as the Host ID, which is confusing to users.

To get around this confusion, simply copy the first 12 characters from the entire string to use as the Host ID string, when you are prompted for it during the license generation process, as shown in the screen shots below.

Monday, July 11, 2011

Connecting GeoMedia Professional to a read/write PostGIS database warehouse

Intergraph has released an open source GeoMedia PostGIS data server under the Apache 2.0 license on this site http://geomediapostgis.codeplex.com/. I downloaded and tried out creating and connecting to a read/write PostGIS warehouse on a Windows server from a remote client using the sample GeoMedia workspace USSampleData.gws. The instructions on the binaries talked about using Debian Linux as the host for the PostGIS database while I used Windows XP as the host instead.

Installing PostGIS 1.5 onto PostgreSQL 9.0 on Windows
After installing PostgreSQL 9.0 on Windows using the packaged installer on my server, I did the following:
  1. Download the PostGIS 1.5 Windows binaries from http://postgis.refractions.net/download/windows/pg90/postgis-pg90-binaries-1.5.3.zip
  2. Extract the files into a folder e.g. C:\Program Files\postgis-pg90-binaries-1.5.3.

  3. Use a text editor and open up the makepostgisdb.bat file.

  4. If necessary, change the PGPORT, PGHOST, PGUSER, and PGPASSWORD settings to match the Windows PostgreSQL installation.
  5. Uncomment the last line to create the database defined by the THEDB setting as a template PostGIS database e.g template_postgis15. Close and save the file.

  6. Run the batch file makepostgisdb.bat.

    PostGIS is installed and a template database is created.
Configure PostgreSQL for network access
By default, PostgreSQL is configured not to accept any network database requests. I had to do edit the configuration parameters to allow network access.
  1. On the server, select Start | All Programs | PostgreSQL 9.0 | pgAdmin III.

    The pgAdmin III application appears.
  2. In the Object browser pane, double click on the PostgreSQL 9.0 (localhost:5432) node. Enter the password if prompted.

    Connection to the server is established.
  3. Select Tools | Server Configuration | pg_hba.conf.

    The Backend Access Configuration Editor appears.
  4. Double click the empty last row.

    The Client Access Configuration dialog appears.
  5. Toggle Enabled on. Choose host for Type, all for Database, all for User and md5 for Method. Type in an appropriate IP Address for your network e.g. 192.168.8.0/24.

    Note: In this example, I am allowing access for any clients with the IP address pattern 192.168.8.*.
  6. Click OK.
  7. Select File | Save. Press Yes if prompted.
  8. Select File | Reload Server. Press Yes if prompted.
  9. Close the Client Access Configuration and Backend Access Configuration dialogs. 
Create and configure the Postgis database
  1. In the Object browser, expand and select Login Roles node.
  2. Select Edit | New Object | New Login Role.

    The New Login Role dialog box appears.
  3. In the Role Name field, type in gdouser. In the Password and Password(again) fields, type in gdouser.

  4. Click OK.

    The login is created.
  5. In the Object browser, select the Database(s) node.
  6. Select Edit | New Object | New Database.

    The New Database dialog box appears.
  7. In the Name field, type in gdotest. Choose gdouser as the Owner. Choose template_postgis15 as the Template.

  8. Click OK.

    The database is created.
Configuring the PostGIS GDO server on the client
  1. On the client machine, I downloaded the PostGISGDObin.zip package from http://geomediapostgis.codeplex.com and extracted to a folder e.g. C:\Program Files\PostGISGDO\.

  2. Run Register.bat.

    The data server is registered with GeoMedia.
  3. Double click the file PsgDBUtils.exe.

    The PostGIS GDO Database Utilities appear.
  4. Click New Connection.

    The New Connection dialog box appears.

  5. In the Server field, type in the address or name. In the Database field, type in gdotest. In the User field, type in gdouser. In the Password field, type in gdouser. Click OK.

    The utility is connected to the PostGIS database.
  6. Click Create INGR Metadata Tables.

    The metadata tables are created.
  7. Click Run script.

    The Open dialog box appears.
  8. Browse and choose the file USSampleProjCS.sql. Click Open. Click OK when prompted.

    Note: this script will add the Albers Equal Area coordinate system to the PostGIS database for working with the sample USSampleData.gws workspace.
  9. Click Close.
Connect to the PostGIS database from GeoMedia
  1. Start GeoMedia and open up the sample workspace USSampleData.gws.
  2. Select Warehouses | New Connection.

    The New Connection dialog box appears.
  3. Choose PostGIS Connection Type.
  4. In the Server field, type in the IP address or node name of the PostGIS server.
  5. In the Database field, type in gdotest.

  6. In the User and Password fields, type in gdouser. Click OK.

    GeoMedia is connected to the PostGIS database.

    Note: You should now have full read/write access to the PostGIS database.

Monday, June 13, 2011

GeoMedia C# code snippet to connect to a WMS server

Recently I was asked to look at some C# code to connect and display a feature from a Web Mapping Service (WMS) server. I wrote some driving GeoMedia code to test out the connection.



//...cut...

//Create the connection to the WMS server
PClient.Connection conn = null;    //connection to the WMS server
MapviewLib.GMMapView map = (MapviewLib.GMMapView) mapWindow.MapView;
conn = (PClient.Connection) this.Application.CreateService("GeoMedia.Connection");
conn.Name = "WMS";
conn.Type = "WMS.GDatabase";
conn.Mode = 0;
conn.Description = "WMS";
conn.Location = "Not used";
conn.ConnectInfo = @"NOCSFFOUND=FAIL;URI=http://some.wms.com/wms.aspx";
conn.Connect();

//Now create a recordset to a WMS feature
PClient.OriginatingPipe OP;
conn.CreateOriginatingPipe(out OP);
OP.Table = "Feature1";

//Build a transformation path to/fro the map view coordinate system and the WMS and store the paths in the map view's CoordSystemsMgr object
PCSS.CoordSystem objCS = null;
PClient.ServerTransService objSTS = (PClient.ServerTransService)this.Application.CreateService("GeoMedia.ServerTransService");
PCSS.AltCoordSystemPath objAltCoordSystemPath = null;
PClient.GField objGeomFld = OP.OutputRecordset.GFields["Geometry"];
objSTS.CreateCSFromGeometryField( objGeomFld, out objCS);
objSTS.CreateSimpleTransFromCSMtoCS(map.CoordSystemsMgr, objCS, out objAltCoordSystemPath);

//Transform the WMS recordset to the map view's coordinate system
PDBPipe.CSSTransformPipe objXPipe = (PDBPipe.CSSTransformPipe)this.Application.CreateService("GeoMedia.CSSTransformPipe");
objXPipe.InputRecordset = (PDBPipe.GRecordset) OP.OutputRecordset;
objXPipe.InputGeometryFieldName = "Geometry";
objXPipe.CoordSystemsMgr = map.CoordSystemsMgr;
objXPipe.OutputCSGUID = map.CoordSystemsMgr.CoordSystem.GUID;

//Now we can use the transformed WMS recordset
PDBPipe.GRecordset wmsRS = objXPipe.OutputRecordset

//...etc...

Monday, January 24, 2011

Import GeoMedia Access Warehouse features into gvSIG

I recently installed and tried out the open source Java GIS application gvSIG OADE version 2010 from Oxford Archaeology along with a free extmdb extension to read features from a GeoMedia Access warehouse from the Google Code project site. I found the process to create a gvSIG project and import GeoMedia features to be relatively straightforward. Maybe the one thing to take note of is that the loaded GeoMedia features are temporary in nature only and must be saved permanently as gvSIG compatible formats e.g. Shape file.

In this example, I am going to import in a feature from the GeoMedia sample warehouse USSampleData.mdb file, which uses the Albers Equal Area coordinate system.

Create a new gvSIG project and assign a coordinate system

  1. Select Start | All Programs | gvSIG OA Digital Edition 2010 | gvSIG OA Digital Edition 2010.

    The gvSIG OADE 2010:Untitled application appears.

  2. In the Project manager window, click View | New.

    An Untitled-0 view is created and added to the View list box.

  3. In the View group box, select Untitled-0. Click Properties.

    The View properties dialog box appears.

  4. Click the Current projection button.

    The Spatial Reference System (SRS) dialog box appears.

  5. Click the Type combo box. Choose a suitable type e.g. ESRI.
  6. Toggle on By name.


  7. In the Search criteria field, type in Albers. Click Search.

    A list of matching results appear.

  8. Select USA_Contiguous_Albers_Equal_Area. Click OK.


  9. Click OK again.
  10. In the View group box, click Open.

    The View:Untitled-0 window is opened.
Import GeoMedia features
  1. Select View | Add Layer.

    The Add Layer dialog box appears.

  2. Click the MDB tab.


  3. Click the Search button.

    The Open dialog box appears.

  4. Browse and select a GeoMedia MDB file e.g. C:\Warehouses\USSampleData.mdb. Click Open.

    The GeoMedia feature names are displayed in the Feature Classes grid.



  5. Toggle on the feature(s) to add, e.g. States. Click OK.

    Processing messages appear and the selected features are imported.

  6. Close the message box.

    The imported features are displayed in the view.
Export GeoMedia feature(s)
  1. In the View legend, click the feature name to be exported e.g. States.
  2. Select Layer | Export To | Shapefile.

    The Save dialog box appears.

  3. Type in the file name e.g. States. Click Save.

    Processing messages appear.
     
  4. Click Yes.

    The exported shapefile is added as a layer to the view.
Remove the GeoMedia warehouse from the view
  1. In the View legend, mouse right click on the warehouse name e.g. USSampleData.

    A pop up menu appears.

  2. Choose Delete.

    A prompt appears.

  3. Click Yes.

    The GeoMedia warehouse is removed from the view.
Save the gvSIG project
  1. Select File | Save project.

    The Save project dialog box appears.

  2. Type in a file name, e.g. geomedia.gvp. Click Save.

    The project is saved.

Monday, October 18, 2010

Batch plotting pdfs from GeoMedia Professional's BatchPlot Utility

Intergraph did not include the capability to plot PDF files from the BatchPlot utility of GeoMedia Professional. Instead Intergraph recommend users to make use of Adobe Distiller to automatically convert any plot files generated by BatchPlot in a watch directory into PDFs.

I have a couple of alternative methods to create PDFs in batch mode. One of the methods involve the use of a free PDF printer called PDFCreator and which I shall describe here. It can be downloaded from this web site. Here is the procedure to use PDFCreator to create PDF files from BatchPlot.


By default, the PDFCreator installer creates a virtual printer with the name PDFCreator. The printer is automatically configured to create temporary PDF documents from any print job submitted to it; and the user will have to manually save the PDF document to a desired name and location. If BatchPlot submits a lot of print jobs to the PDFCreator printer, then manual saving would be quite troublesome. So it would be better if we enable the Auto-Save feature for the PDFCreator printer and define an output print folder.

Configure PDFCreator

  1. Select Start | All Programs | PDFCreator | PDFCreator.

    The PDFCreator - PDF Print monitor dialog box appears.
  2. Select Printer | Options.

    The Options dialog box appears.
  3. On the list on the left side, select Auto-save.
  4. Toggle on Use Auto-save.
  5. Toggle on Use this directory for auto-save.
  6. Click [...] and select a directory.

  7. Ensure After auto-saving open the document with the default program is toggled off.

    Note: by default, the PDF file is saved with the prefix {datetime}. I could not find a way to automatically name it from BatchPlot. So datetime is the best alternative.
  8. Click Save.
Use BatchPlot to submit print jobs to PDFCreator
  1. On the Windows Desktop, select Start | All Programs | GeoMedia Professional | Utilities | Batch Plotting.

    The Batch Plotting dialog box appears.
  2. Select File | Open. Browse and choose a saved Batch Plotting File e.g. batchPlot.gbp. Click Open.

  3. Select File | Print.

    The Print dialog box appears.
  4. In the Name combo box, choose PDFCreator.
  5. Click OK.

    BatchPlot submits print jobs to the PDFCreator printer.


    The PDFCreator Print monitor shows the list of submitted print jobs.


    Finally, the PDF files are created in the output directory.


    The only problem with this method is that the PDF files must be renamed manually. Note that the plot order is in the same order as the order BatchPlot reads the map content features from the input warehouse - knowing this can help a little in renaming the files correctly