Showing posts with label geomedia Professional. Show all posts
Showing posts with label geomedia Professional. 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, 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, December 19, 2011

Accessing PostGIS database features from gvSIG

The PostGIS spatial database can be accessed by a variety of client software including gvSIG, FME, and even Intergraph's GeoMedia. It is possible to import features from GeoMedia into the PostGIS database and manipulated through an open source software like gvSIG. For instance, the example States feature in the screenshots below was imported to PostGIS via GeoMedia's Export Feature command.

In order for gvSIG to access and manipulate features in PostGIS, a GeoDB connection must be made first as shown below.
  1. Start gvSIG OADE 2010. Create a new View with the desired coordinate system, e.g. Albers Equal Area. Open the view.


  2. Select View | Add Layer.

    The Add Layer dialog box appears.

  3. Click the GeoDB tab.
  4. In the Connection field, click the New Connection button on the right.|

    The Connection Settings dialog box appears.

  5. In the Connection name field, type in a name e.g. PostGISConn1.
  6. In the Driver field, choose PostGIS JDBC Driver.
  7. In the Server URL or IP field, type in the address name or the IP address e.g. 192.168.1.99.
  8. In the Database name field, type in the PostGIS database name e.g. gdotest.
  9. In the User field, type in the database user name e.g. gdouser.
  10. In the Password field, type in the password of the database user e.g. gdouser.
  11. Click OK.

    If the values are correctly filled, the database would be connected to gvSIG. A list of tables appear

  12. In the table list field, toggle on one or more spatial tables e.g. public.states.
  13. Click Ok.

    The selected table(s) are displayed in the View.

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, December 6, 2010

Export a GeoMedia Access Warehouse to Postgis with GM2PGSQL

If you have been using Postgis for a while, you would be familiar with the shp2pgsql executable. This executable converts a shapefile into a Postgis SQL file for bulk loading into a Postgis database. There is a similar executable for converting a GeoMedia Access warehouse into Postgis. It is gm2pgsql, a free executable which is downloadable from this web site http://gm2pgsql.projects.postgresql.org/.

To use this executable,
  1. Type in the gm2pgsql command at the Windows Command Prompt.

    For example, input.mdb is the source GeoMedia Access warehouse, output.sql is the destination Postgis SQL file, pgdatabase is the destination Postgis database schema name, and -1 is the SRID number.

    C:\> gm2pgsql input.mdb output.sql pgdatabase -1
  2. Press RETURN.

    All the supported features in the Access warehouse are exported out.
If you open up the resultant SQL file with Notepad, the SQL statements to create the corresponding Postgis tables and corresponding feature attributes and geometries can be seen, as shown below. 
It seems that there is no way to limit the export to a single feature table; it will export all features that it recognizes. For more details, please visit the gm2pgsql project page at http://gm2pgsql.projects.postgresql.org/.

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

Wednesday, September 8, 2010

Intergraph introduces GeoMedia 3D

I haven't got a chance  to try out GeoMedia 3D but it certainly looks promising. It's an add-on to the core GeoMedia product, which adds in an additional 3D Map window seamlessly into the framework and you could manipulate and query the features just like in the basic 2D map window.

Monday, April 26, 2010

Now GeoMedia can read ArcView Projection Files (*.prj)

The recent GeoMedia hot fix 6.1.7.16 added a new function in the Define Coordinate System File utility to load ArcView coordinate projection files (*.prj). Previously, you could only read in coordinate systems from Microstation type 56 elements in design files (*.dgn) and other GeoMedia coordinate system files (*.csf). Reading in the prj file is similar to reading in the dgn and csf files as shown below.
  1. Click Start | All Program | GeoMedia Professional | Utilities | Define Coordinate System File.

    The Define Coordinate System File dialog appears.


  2. Click Load.

    The Load Coordinate System From File dialog appears.





  3. Click the Files of Type combo box. Choose Projection Files (*.prj). Choose a *.prj file on your system. Click Open.

    The coordinate system is read.

Tuesday, March 30, 2010

Getting the Primary Geometry Field Name from a GRecordset

As a GeoMedia programmer, it is necessary to be able to determine the primary geometry field name of a feature's GRecordset at runtime. The database field in the record set  that stores the feature geometry in a GeoMedia warehouse is typically named as Geometry1 but it is not always the case. Sometimes it can be simply Geometry or GDO_GEOMETRY or any name the programmers encoded into the application commands.

 If you are doing any programming using GeoMedia, then it is possible that at some point you would need to determine the primary geometry field name by code. You can use the ExtendedPropertySet class to directly read the primary geometry field name of record sets generated through the originating pipe object. Failing that, you can loop through all the fields of the record set to find the fields of type gdbSpatial or gdbGraphic. An example C# method is shown below:


        public static string GetGeometryFieldName(PClient.GRecordset rs)
        {
            string geomFieldName = string.Empty;
            PClient.ExtendedPropertySet exPropSet;
            PClient.GField field = null;
 
            exPropSet = (PClient.ExtendedPropertySet)rs.GetExtension("ExtendedPropertySet");
            geomFieldName = (string)exPropSet.GetValue("PrimaryGeometryFieldName");
 
            if (geomFieldName.Length == 0)
            {
                foreach (PClient.GField fld in rs.GFields)
                {
                    if (fld.Type == GDO.GConstants.gdbSpatial | fld.Type == GDO.GConstants.gdbGraphic)
                    {
                        geomFieldName = fld.Name;
                        break;
                    }
                }
            }
            if (exPropSet != null) Marshal.FinalReleaseComObject(exPropSet);
            if (field != null) Marshal.FinalReleaseComObject(field);
            return geomFieldName;
 
        }

Sunday, March 21, 2010

GeoMedia Grid's LiDAR Files to Text Files Utility

GeoMedia Grid 6.1.1 has one additional tool to work with LiDAR LAS files - the LiDAR Files to Text Files utility. As the name indicates, this utility will convert one or more LAS files into ASCII text files. If you find that converting LAS files to GeoMedia feature classes take too long and you have a lot of disk space, then you could use this utility to convert first to text files before creating native GeoMedia Grid *.mfm files. Besides creating the text files, this utility will also create the GeoMedia text server file definition file (*.tfd) for convenience. With this *.tfd file, you simply use the GeoMedia Warehouse Connection Wizard to connect to the LiDAR text files.

Here are the steps to use the LiDAR Files to Text Files Utility.
  1. From the Windows Desktop, select Start | All Programs | GeoMedia Grid | Utilities | LiDAR Files to Text Files.

    The LiDAR Files to Text File dialog box appears.
  2. Click Add. And choose a LiDAR LAS file.

    The selected LAS file is added to the Input LiDAR files list.
  3. In the Output text file name field, click Browse.

    The Save As dialog box appears.
  4. In the File name field, type in an output name. Click Save.

    The Apply button becomes enabled.
  5. Click Apply.

    The LAS file is converted into a text file and the LiDAR Files to Text File Log Summary is displayed.
  6. Click Close
As shown below, besides the output text file a GeoMedia *.tfd file is also created.

This *.tfd file can be used when you make a connection to the newly created text file with the Warehouse | New Connection command in GeoMedia as shown below.

After filling in the input text file, text format definition file and the coordinate system file, the New Connection dialog box should like the figure below.

Once connected, the contents of the text file can be displayed in GeoMedia's Data Window.

Wednesday, February 10, 2010

Import ArcGrid ASCII files into GeoMedia Grid

ArcGrid ASCII files are convenient to pass data between application software. Before using terrain data in ArcGrid ASCII format files (*.asc, *.agr), they must be imported into GeoMedia Grid's native format raster files (*.mfm) and placed as layers under what is termed a Study Area. I have no idea what .mfm stands for and I could not find any documentation details on the extension name. 

To import an ArcGrid ASCII file, the following steps can be done. 
  1. Run GeoMedia and open up or create a GeoWorkspace with the desired coordinate system and a read/write warehouse connection.

  2. Select Grid | Study Area | Import File(s).

    The Import File(s) dialog box appears.


  3. Click Browse and select an ArcGrid ASCII file e.g. B3.asc.



  4. Click Open.

    The File Type(s) Found dialog box may appear.


  5. Choose ArcGrid ASCII. Click OK.

  6. Click the Coordinate system file Browse button. Choose the appropriate coordinate system file (*.csf) and click Open.

    The Import File(s) dialog box is updated with the selected.

  7. Click Next.

    The selected file is scanned and then the ASC Input data dialog box appears.

  8. Click the X Coordinate and Y Coordinate units drop down list and select the appropriate horizontal units e.g. feet.

  9. In the Cell resolution text field, type in the correct cell spacing e.g. 2.

  10. In the Cell resolution units drop down list, select the correct vertical units e.g. feet.

    At this point, the ASC Input data dialog box may look like this.

  11. Click OK.

    The Import File(s) dialog box appears.


    Note: By default the Study Area name will be Study Area 1. Right click on the name to rename it to something else if necessary.

  12. Click Next.

    The Import File(s) dialog box is updated with statistical information about the file.

  13. Click Finish.

    The ArcGrid ASCII file is imported into GeoMedia Grid and is ready to be used.