[fdo-users] Set spatial context to MySQL DataStore
popovictamara
popovictamara91 at hotmail.com
Wed Jul 18 01:51:05 PDT 2018
Hello,
i have created MySQL Datastore, and I am trying to use IConnection object to
set spatial context and assign coordinate system to datastore, but i can't
get it to work. Not getting any exceptions, the code runs, but coordinate
system is not assigned. I write in C# and I am following FDO Developers
Guide example.
*
Example No.1:*
// Create spatial context, including coordinate system
AcMapMap currentMap = AcMapMap.GetCurrentMap();
string mapSRS = currentMap.GetMapSRS();
ICreateSpatialContext createSCCmd =
conn.CreateCommand(CommandType.CommandType_CreateSpatialContext)
as ICreateSpatialContext;
createSCCmd.CoordinateSystemWkt = mapSRS;
createSCCmd.Name = "";
createSCCmd.CoordinateSystem = mapSRS;
createSCCmd.Extent = new byte[] { 0, 0, 0, 0 };
createSCCmd.Description = "Description";
createSCCmd.XYTolerance = 0.0;
createSCCmd.ZTolerance = 0.0;
createSCCmd.Execute();
*Example No.2:*
DirectPositionImpl lowerLeft = new DirectPositionImpl();
lowerLeft.X = -180.0;
lowerLeft.Y = -90.0;
DirectPositionImpl upperRight = new DirectPositionImpl();
upperRight.X = 180.0;
upperRight.Y = 90.0;
FgfGeometryFactory geomFactory = new FgfGeometryFactory();
IEnvelope envelope = geomFactory.CreateEnvelope(lowerLeft, upperRight);
IGeometry geom = geomFactory.CreateGeometry(envelope);
byte[] extent = geomFactory.GetFgf(geom);
spatialContextWriter.CoordinateSystem = "WGS 84";
spatialContextWriter.CoordinateSystemWkt = "GEOGCS [ \"Longitude / Latitude
(WGS 84)\", DATUM [\"WGS 84\", SPHEROID [\"WGS 84\", 6378137,
298.257223563]], PRIMEM [ \"Greenwich\", 0.000000 ], UNIT \"Decimal
Degree\", 0.01745329251994330]]";
spatialContextWriter.Description = "This Coordinate System is used for
GPS.";
spatialContextWriter.ExtentType =
SpatialContextExtentType.SpatialContextExtentType_Static;
spatialContextWriter.Extent = extent;
spatialContextWriter.Name = "WGS84";
spatialContextWriter.XYTolerance = 0.001;
*And this is my code: *
FgfGeometryFactory geomFactory = new FgfGeometryFactory();
IniFile iniFile = new IniFile(Paths.Info);
string wkt = iniFile.Read("wkt", "WKT");
double xmin = double.Parse(iniFile.Read("xmin", "EXTENTS"));
double xmax = double.Parse(iniFile.Read("xmax", "EXTENTS"));
double ymin = double.Parse(iniFile.Read("ymin", "EXTENTS"));
double ymax = double.Parse(iniFile.Read("ymax", "EXTENTS"));
ICreateSpatialContext createSpatialContext =
conn.CreateCommand(CommandType.CommandType_CreateSpatialContext) as
ICreateSpatialContext;
createSpatialContext.Name = iniFile.Read("name", "SPATIALCONTEXT");
createSpatialContext.CoordinateSystem = wkt;
createSpatialContext.CoordinateSystemWkt = wkt;
createSpatialContext.Description = iniFile.Read("name", "SPATIALCONTEXT");
DirectPositionImpl lowerLeft = new DirectPositionImpl(xmax, ymin);
DirectPositionImpl upperRight = new DirectPositionImpl(xmin, ymax);
IEnvelope envelope = geomFactory.CreateEnvelope(lowerLeft, upperRight);
IGeometry geom = geomFactory.CreateGeometry(envelope);
byte[] extent = geomFactory.GetFgf(geom);
// a static extent is defined once and never changed
// a dynamic extent grows to accommodate the geometries added to the data
store
createSpatialContext.ExtentType =
SpatialContextExtentType.SpatialContextExtentType_Static;
createSpatialContext.Extent = extent;
createSpatialContext.XYTolerance = 0.00;
createSpatialContext.ZTolerance = 0.00;
createSpatialContext.Execute();
*this is wkt I use:*
PROJCS["MGI 1901 / Balkans zone 6",
GEOGCS["MGI 1901",
DATUM["MGI_1901",
SPHEROID["Bessel 1841",6377397.155,299.1528128,
AUTHORITY["EPSG","7004"]],
TOWGS84[682,-203,480,0,0,0,0],
AUTHORITY["EPSG","1031"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","3906"]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",18],
PARAMETER["scale_factor",0.9999],
PARAMETER["false_easting",6500000],
PARAMETER["false_northing",0],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
AUTHORITY["EPSG","3908"]]
--
Sent from: http://osgeo-org.1560.x6.nabble.com/FDO-Users-f3898664.html
More information about the fdo-users
mailing list