ThinkGeo.com    |     Documentation    |     Premium Support

Shape files from different coordiante systems

Hi,


I have shapefiles in different coordinate systems (some are in geographic and some are in projected coordinate systems) and I would like to view them all in one coordinate systems using MapSuite. My question is, can MapSuite perform on-the-fly coordinate system reprojection on all the shapefiles?  If so how can I do this?


And also how can set the coordinate system info on winformMap control?


Thank you,


Suresh


 


 


 



Suresh,

Yes we can do it. You just need to unify the data into one coordinate system which you’d like to display under. Here is a sample, say I have 2 shape files, one is for Kansas which is in WGS84; the other is for Lawrence which is in UTM. To display them in one map, we should convert the Kansas map from WGS84 to the UTM Lawrence map uses (or the verse way).  Here is the code.



        private void DisplayMap_Load(object sender, EventArgs e)
        {
            // As we will show the map using UTM, we need to set the unit to meter.
            winformsMap1.MapUnit = GeographyUnit.Meter;

            // The following Kansas data is in WGS84 Decimal Degree
            ShapeFileFeatureLayer WGS84Layer = new ShapeFileFeatureLayer(@“C:\wgs84Kansas.shp”);
            WGS84Layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.County1;
            WGS84Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            // The following Lawrence data is in UTM
            ShapeFileFeatureLayer utmLayer = new ShapeFileFeatureLayer(@“c:\utmLawrence.shp”);
            utmLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.County2;
            utmLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            // Convert the wgs84 data into UTM on the fly. Let’s say 4326 and 23030 are the epsg numbers of Geodetic and UTM
            Proj4Projection proj4 = new Proj4Projection(4326, 23030);
            WGS84Layer.FeatureSource.Projection = proj4;

            winformsMap1.StaticOverlay.Layers.Add(“wgs84Kansas”, WGS84Layer);
            winformsMap1.StaticOverlay.Layers.Add(“utmLawrence”, utmLayer);

            winformsMap1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
            winformsMap1.CurrentExtent = new RectangleShape(-120.0, 83.0, 90.0, 40.0);
            winformsMap1.RefreshDynamic();
        }



Ben.

Hi Ben,


Thank you for your reply. I have couple of questions on the code you provided me.


1. On "GeographicUnit" enum, there are only few units. But my requirement is that user can set any unit like Survey Feet, miles, kilometers ...etc. Is it possible to set these units on winformsMap control?


2.  You are creating Proj4Projection object using epsg numbers. In my application I need to get it programatically either from the shapefile or from .prj file. I cannot ask the user to provide these numbers. Can I get the epsg codes of a coordinate system from .prj file or from shape file?


3. I saw that you are setting  "CurrentExtent" to some hardcoded values. As we are trying to display multiple shapefiles, we need to set the minimum bounding rectangle of all the shapefiles programatically. Is my understanding correct? If so then how can I set that?


Thanks for your answers and it is helping me a lot to evaluate the product. As I told you before we are trying to replace MapObjects from our application with MapSuite and I am currently evaluating if MapSuite is right candidate for us or not.


Suresh



Suresh, 
   I can help you with these questions. 
  
 1.  The GeographicUnit is strictly used to reflect the unit of the map data.  In my years of experience maps are only in Feet, Meters, or Decimal Degrees.  This is of course how the data is encoded in the source.  You can however get the results of queries etc in different units using the enumeration DistanceUnit.  It works like this…  You have a map that is in UTM or some other meters projection.  The GeographUnit will be meters.  Next you want to measure the distance between two positions.  When you call the GetDistance method it asks you to pass in a distance unit, this allows you to see the results in any DistanceUnit regardless of the unit the map is in.  The same holds true for AreaUnit if you were to GetArea().  The units we support for distance and area are below.  If you need different AreaUnits or DisanceUnits then just let us know an we can easily add them. 
  
 Areas:  SquareMeters, Acres, Hectares , SquareFeet, SquareKilometers, SquareMiles, SquareUsSurveyFeet , SquareYards 
  
 Distances:  Meter, Feet, Kilometer, Mile, UsSurveyFeet, Yard 
  
 2.  Can you send us some examples of the prj files?  We will look into seeing what we can do to automate the process. 
  
 3.  Yes you can do this.  All you need to do is to take the layer and do something like this. (note this code is just pseduocode) 
  
 layer.Open(); 
 RectangleShape newExtent = layer.GetFullExtent(); 
 layer.Close(); 
  
 If you have many layers you can do this trick. 
  
 newExent.ExpandToinclude(layer2.GetFullExtent()); 
  
 Off of the RectangleShape you can call this ExpandToInclude method and it will expand the rectangle based on other rectangles.   There are a few other ways to do this as well. 
  
 4.  On the replacement of MapObjects I am confident we can do anything they can do.  Map Objects is really old and not extensible.  We are on such a flexible architecture anything is possible.  This is a big plus for both of us, it allows you to extend our stuff if you don’t want our help and it willows our support and professional services to extend our stuff to meet nearly any requirements you have. 
  
 David 


David, 
  
 Thanks for your replies. The shapefiles that I have are in different coordinate systems. When I make "layer.GetFullExtent()" then, do I get the extents in source coordiante system or in the target coordinate system. I feel like we get in source coordinate system. I guess I need to transform it to the target coordinate system. 
  
 As all the information about coordinate systems is available with shape files, I wish we have a simple call where I just add the sahpe files to the winformsMap control and which in turn performs the transformation to the target coordinate system and displays the shape files correctly. 
  
 Thank you, 
 Suresh

David, 
  
 I could not find "GetFullExtent()" call on layer object. I could find "GetBoundingBox()" call on it. Do you meant by this? If not I guess I am missing something. 
  
 Thanks, 
 Suresh 


Suresh,


I think what David means should be GetBoundingBox(), which gets the full extent of one layer.
 
GetBoundingBox() will get the full extent in target coordinate system and you don’t need to do the transform yourself. The snapshot as following gives you an example how to get the full extent before/after the projection.


We don’t support .prj file, which means we don’t know what projection one shape file is unless we set it explicitly in the code. That’s why we cannot simply set one target coordinate system and automatically transform all the shape layers from all kinds of projections to the target one. Maybe in the future we will have an assistant file similar to “.prj” which records the shape file’s projection info, and then we can do it.


 
For now, I think you need to get the projection from the prj file yourself and set it explicitly in the code. It is more work but you can see from the sample that it’s just a couple lines of code and not so hard.
 
Hope that answers your question and any more queries just let me know.
 
Ben

Ben, 
  
 prj file format is very popular in the industry and even OGC adapted it for its WellKnown Text format. Not supporting the prj files is going to be show stopper for us.

Suresh,


Thanks for letting me know. I will write it down to our TODO list and hand it to the Discussion of new features for the next release, I have a feeling we will work on it pretty soon.
 
Also I got some tif files from you and I confirmed we can't support those kinds of tiff files.  Now to work around, you can use the attached tools to convert the file into another kind of tiff files, which can be used in the current version. We will still work on supporting more tiff types .
 
Ben.

153-Tiff2Rgba.zip (74.4 KB)