Quantcast

Shapefile and spatial context

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Shapefile and spatial context

hanko
According to wikipedia:

Shapefile projection format (.prj)

The projection information contained in the .prj file is critical in order to understand the data contained in the .shp file correctly.
Although it is technically optional, it is most often provided, as it is not necessarily possible to guess the projection of any given points.
The file is stored in well-known text (WKT) format.

Some typical information contained in the .prj file is:
    * Geographic coordinate system
        -------------
I create a new spatial context
Then I create a new chema with a few Feature Classes.
I set geom.SpatialContextAssociation = newSpatialContext.Name;

When I apply schema for every Feature Class are created a bunch of files
with the same name as Feature Class (shp, shx, idx, dbf, cpg).
I wonder why is not a PRJ file created for each Feature Class automatically.

private void CreateSpatialContext()
{
        string wkt = "GEOGCS [ \"Longitude / Latitude (WGS 84)\", DATUM [\"WGS 84\", SPHEROID [\"WGS 84\", 6378137, 298.257223563]], PRIMEM [ \"Greenwich\", 0.000000 ], UNIT \"Decimal Degree\", 0.01745329251994330]]";

        using (ICreateSpatialContext create = _conn.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType_CreateSpatialContext) as ICreateSpatialContext)
        {
                using (FgfGeometryFactory geomFactory = new FgfGeometryFactory())
                {
                        DirectPositionImpl lowerLeft = new DirectPositionImpl();
                        lowerLeft.X = -180.0;
                        lowerLeft.Y = -90.0;
                        DirectPositionImpl upperRight = new DirectPositionImpl();
                        upperRight.X = 180.0;
                        upperRight.Y = 90.0;
                        create.CoordinateSystemWkt = wkt;
                        //MyStream.Write(create.CoordinateSystemWkt);
                        //MyStream.Close();
                        create.Description = "This Coordinate System is used for GPS.";
                        create.ExtentType = SpatialContextExtentType.SpatialContextExtentType_Static;

                        IEnvelope envelope = geomFactory.CreateEnvelope(lowerLeft, upperRight);
                        IGeometry geom = geomFactory.CreateGeometry(envelope);
                        create.Extent = geomFactory.GetFgf(geom);
                        create.Name = _spatialContext;
                        create.UpdateExisting = false;
                        create.XYTolerance = 0.001;
                        create.ZTolerance = 0.001;
                        create.Execute();
                        if (geom != null)
                                geom.Dispose();
                }
        }
}



I create a file containing the WKT text.
TextWriter MyStream = null;
string prjFile = @"C:\Temp\SHP\Ship.prj";
MyStream = File.CreateText(prjFile);
MyStream.Write(wkt);
MyStream.Close();



Cheers Hanko
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Shapefile and spatial context

gisbradokla
Hanko,
  I find that often FDO has a problem reading prj files. One method I have used is that when I am creating a file in map and I have already assigned a projection I then "re-project" when exporting. that is I just re-assign the projection in the last tab of the export dialog even though it is the same projection. This forces map to creat the prj. which I then find is in the correct format.
If the file is being used in a persistent manner in a adwg you can select the (unknown) file and edit the coordinate system which then will persist each time you open the drawing that it is attached to.
Brad

On Fri, Jun 11, 2010 at 2:59 AM, hanko <[hidden email]> wrote:

According to wikipedia:

Shapefile projection format (.prj)

The projection information contained in the .prj file is critical in order
to understand the data contained in the .shp file correctly.
Although it is technically optional, it is most often provided, as it is not
necessarily possible to guess the projection of any given points.
The file is stored in well-known text (WKT) format.

Some typical information contained in the .prj file is:
   * Geographic coordinate system
       -------------
I create a new spatial context
Then I create a new chema with a few Feature Classes.
I set geom.SpatialContextAssociation = newSpatialContext.Name;

When I apply schema for every Feature Class are created a bunch of files
with the same name as Feature Class (shp, shx, idx, dbf, cpg).
I wonder why is not a PRJ file created for each Feature Class automatically.

private void CreateSpatialContext()
{
       string wkt = "GEOGCS [ \"Longitude / Latitude (WGS 84)\", DATUM [\"WGS
84\", SPHEROID [\"WGS 84\", 6378137, 298.257223563]], PRIMEM [
\"Greenwich\", 0.000000 ], UNIT \"Decimal Degree\", 0.01745329251994330]]";

       using (ICreateSpatialContext create =
_conn.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType_CreateSpatialContext)
as ICreateSpatialContext)
       {
               using (FgfGeometryFactory geomFactory = new FgfGeometryFactory())
               {
                       DirectPositionImpl lowerLeft = new DirectPositionImpl();
                       lowerLeft.X = -180.0;
                       lowerLeft.Y = -90.0;
                       DirectPositionImpl upperRight = new DirectPositionImpl();
                       upperRight.X = 180.0;
                       upperRight.Y = 90.0;
                       create.CoordinateSystemWkt = wkt;
                       //MyStream.Write(create.CoordinateSystemWkt);
                       //MyStream.Close();
                       create.Description = "This Coordinate System is used for GPS.";
                       create.ExtentType =
SpatialContextExtentType.SpatialContextExtentType_Static;

                       IEnvelope envelope = geomFactory.CreateEnvelope(lowerLeft, upperRight);
                       IGeometry geom = geomFactory.CreateGeometry(envelope);
                       create.Extent = geomFactory.GetFgf(geom);
                       create.Name = _spatialContext;
                       create.UpdateExisting = false;
                       create.XYTolerance = 0.001;
                       create.ZTolerance = 0.001;
                       create.Execute();
                       if (geom != null)
                               geom.Dispose();
               }
       }
}

http://osgeo-org.1803224.n2.nabble.com/file/n5166854/ship.bmp

I create a file containing the WKT text.
TextWriter MyStream = null;
string prjFile = @"C:\Temp\SHP\Ship.prj";
MyStream = File.CreateText(prjFile);
MyStream.Write(wkt);
MyStream.Close();

http://osgeo-org.1803224.n2.nabble.com/file/n5166854/ship_coord.bmp

Cheers Hanko
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Shapefile-and-spatial-context-tp5166854p5166854.html
Sent from the FDO Users mailing list archive at Nabble.com.
_______________________________________________
fdo-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/fdo-users



_______________________________________________
fdo-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/fdo-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Shapefile and spatial context

Dan Stoica
In reply to this post by hanko
Hi,

> I wonder why is not a PRJ file created for each Feature Class automatically.

The PRJ is created automatically provided that the geometry property of your feature class has been associated with a spatial context:

        geometryProp->SetSpatialContextAssociation(_spatialContext);

Also note the provider is not creating empty PRJ files.

Dan.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of hanko
Sent: Friday, June 11, 2010 4:00 AM
To: [hidden email]
Subject: [fdo-users] Shapefile and spatial context


According to wikipedia:

Shapefile projection format (.prj)

The projection information contained in the .prj file is critical in order
to understand the data contained in the .shp file correctly.
Although it is technically optional, it is most often provided, as it is not
necessarily possible to guess the projection of any given points.
The file is stored in well-known text (WKT) format.

Some typical information contained in the .prj file is:
    * Geographic coordinate system
        -------------
I create a new spatial context
Then I create a new chema with a few Feature Classes.
I set geom.SpatialContextAssociation = newSpatialContext.Name;

When I apply schema for every Feature Class are created a bunch of files
with the same name as Feature Class (shp, shx, idx, dbf, cpg).
I wonder why is not a PRJ file created for each Feature Class automatically.

private void CreateSpatialContext()
{
        string wkt = "GEOGCS [ \"Longitude / Latitude (WGS 84)\", DATUM [\"WGS
84\", SPHEROID [\"WGS 84\", 6378137, 298.257223563]], PRIMEM [
\"Greenwich\", 0.000000 ], UNIT \"Decimal Degree\", 0.01745329251994330]]";

        using (ICreateSpatialContext create =
_conn.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType_CreateSpatialContext)
as ICreateSpatialContext)
        {
                using (FgfGeometryFactory geomFactory = new FgfGeometryFactory())
                {
                        DirectPositionImpl lowerLeft = new DirectPositionImpl();
                        lowerLeft.X = -180.0;
                        lowerLeft.Y = -90.0;
                        DirectPositionImpl upperRight = new DirectPositionImpl();
                        upperRight.X = 180.0;
                        upperRight.Y = 90.0;
                        create.CoordinateSystemWkt = wkt;
                        //MyStream.Write(create.CoordinateSystemWkt);
                        //MyStream.Close();
                        create.Description = "This Coordinate System is used for GPS.";
                        create.ExtentType =
SpatialContextExtentType.SpatialContextExtentType_Static;

                        IEnvelope envelope = geomFactory.CreateEnvelope(lowerLeft, upperRight);
                        IGeometry geom = geomFactory.CreateGeometry(envelope);
                        create.Extent = geomFactory.GetFgf(geom);
                        create.Name = _spatialContext;
                        create.UpdateExisting = false;
                        create.XYTolerance = 0.001;
                        create.ZTolerance = 0.001;
                        create.Execute();
                        if (geom != null)
                                geom.Dispose();
                }
        }
}

http://osgeo-org.1803224.n2.nabble.com/file/n5166854/ship.bmp 

I create a file containing the WKT text.
TextWriter MyStream = null;
string prjFile = @"C:\Temp\SHP\Ship.prj";
MyStream = File.CreateText(prjFile);
MyStream.Write(wkt);
MyStream.Close();

http://osgeo-org.1803224.n2.nabble.com/file/n5166854/ship_coord.bmp 

Cheers Hanko
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Shapefile-and-spatial-context-tp5166854p5166854.html
Sent from the FDO Users mailing list archive at Nabble.com.
_______________________________________________
fdo-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/fdo-users
_______________________________________________
fdo-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/fdo-users
Loading...