[mapguide-users] Re: Inserting features in PostGIS fails
ar_gaeta
ar_gaeta at yahoo.it
Mon Dec 20 08:35:19 EST 2010
Hi Jackie, Hi all.
I come back on working to modify features online. I'm still on a big
problem: add a geometry on Postgis.
How have I work to achieve this goal?
I've read a lot of forum but all are talking about to develop code in C# or
in .NET. I'm using MGOS 2.2, with Apache/Tomcat (Java), with FDO version
3.5, PostgreSQL Provider.
I attach here my code. It works to add feature in SDF file, but I'm not able
to understand why it's no good for PostGIS.
I must add a row somewhere? I must import some ".dll" somewhere?
Thanks for any any help...
Code .jsp:
//I just import these pages:
<%@ page import="org.osgeo.mapguide.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.text.*" %>
<%@ page import="javax.servlet.jsp.*" %>
<%@ page import="javax.servlet.http.*" %>
//And this is the "try" code, that give me this error: "FDO exception. The
schema doesn't exist".
try {
String sessionId = request.getParameter("SESSION");
String mapName = request.getParameter("MAPNAME");
String realpath = getServletContext().getRealPath("/");
// Initialize web tier with the site configuration file. The config
// file should be in the same folder as this script.
String configPath = realpath + "webconfig.ini";
MapGuideJavaApi.MgInitializeWebTier( configPath );
// Get the user information using the session id,
// and set up a connection to the site server.
MgUserInformation userInfo = new MgUserInformation(sessionId);
MgSiteConnection siteConnection = new MgSiteConnection();
siteConnection.Open(userInfo);
MgSite site = new MgSite();
site.Open(userInfo);
// Get an instance of the required service(s).
MgResourceService
resourceService=(MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
MgFeatureService
featureService=(MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
//A quanto pare specificando "siteConnection" per creare la mappa, dopo
posso usare "MgLayer.UpdateFeatures()": ma cosa cambia? Così come è cmq a me
funziona...
MgMap map = new MgMap(siteConnection);
map.Open(mapName);
//Here I put the resource for my Postgis layer:
MgResourceIdentifier fdo = new
MgResourceIdentifier("Library://prova_basic/Load_procedures/postgresql.FeatureSource");
//This is the name of my layer based on Postgis table "public:points":
String layername = "points";
//Specify the property values
MgPropertyCollection properties = new MgPropertyCollection();
MgAgfReaderWriter agfWriter = new MgAgfReaderWriter();
MgGeometryFactory geoFactory = new MgGeometryFactory();
MgLinearRingCollection LinearRingCollection = new MgLinearRingCollection();
MgCoordinateCollection coordcol = new MgCoordinateCollection();
double x = Double.parseDouble(coods[0]);
double y = Double.parseDouble(coods[1]);
MgCoordinate coordinate = geoFactory.CreateCoordinateXY(x, y);
coordcol.Add(coordinate);
MgPoint point = geoFactory.CreatePoint(coordinate);
//Proviamo con queste righe prese dal forum salvato sul desktop...niente:
MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter();
String pointstring = "POINT XY (" + Double.toString(x) + " " +
Double.toString(y) + ")";
MgGeometry geometry = (MgPoint) wktReaderWriter.Read(pointstring);
MgByteReader geometryByteReader = agfWriter.Write(geometry);
//The field "the_geom" is the geometry field of my postgis table, and
FeatId is mandatory:
properties.Add(new MgGeometryProperty("the_geom", geometryByteReader));
properties.Add(new MgInt32Property("FeatId", 25));
MgInsertFeatures insertFeature1 = new MgInsertFeatures(layername,
properties);
MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
commands.Add(insertFeature1);
//set_ResourceWriteAble(fdo, resourceService);
layer.UpdateFeatures(commands);
//I try also this way to update the feature but doesn't work:
//featureService.MgUpdateFeatures(fdo, commands, false);
layer.ForceRefresh();
map.Save(resourceService);
}
catch (MgException e)
{
out.println("<p><strong>Error:</strong> ");
out.println(e.GetDetails());
out.println("</p>");
System.out.println(e.GetDetails());
}
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Inserting-features-in-PostGIS-fails-tp1813557p5850790.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list