Infrastructure Map Server Forum
Welcome to Autodesk’s Infrastructure Map Server Forums. Share your knowledge, ask questions, and explore popular Infrastructure Map Server topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help me :- Error on layer.updatefeature

5 REPLIES 5
Reply
Message 1 of 6
naveen2010
1070 Views, 5 Replies

Help me :- Error on layer.updatefeature

I m new in mapguide 2010, i want to filter on layer data which connected with oracle db. Kindly somebody help me about this.

 

MgFeatureCommandCollection updateCommands = new MgFeatureCommandCollection();

updateCommands.Add (new MgDeleteFeatures ("Point", "clientid like '2%'"));

layer = map.GetLayers().GetItem("Point");

layer.UpdateFeatures(commands);

layer.Visible = true;
layer.ForceRefresh();


Above code throwing "null" Error on this: layer.updatefeature.


Please somebody help me......

 

Thanks  in Advance

 

5 REPLIES 5
Message 2 of 6
studio
in reply to: naveen2010

I've got the same problem: did you solve it?!

My code is in Java, and is a bit different:

 

MgDeleteFeatures deleteFeature1 = new MgDeleteFeatures("area","nome='primo'");
MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
commands.Add(deleteFeature1);
MgLayer layer = (MgLayer)map.GetLayers().GetItem("area");
layer.UpdateFeatures(commands);

 

I think there is something wrong on the last string but I don't understand what.

I'm working on MGOS 2.2, with bundled configuration with Java.

 

Thanks in advance if you can help me!

Message 3 of 6
jackie.ng
in reply to: naveen2010

How did you create your map?

 

Like this?

 

MgMap map = new MgMap();

 

Or this?

 

MgSiteConnection conn = new MgSiteConnection();

...

MgMap map = new MgMap(conn);

 

 

 

MgLayer.UpdateFeatures() requires that the MgMap be created with the second constructor

 

- Jackie

Message 4 of 6
studio
in reply to: naveen2010

I've modified the entire file in this way (see following rows) and now it works. But what is the difference for open a map between:

MgMap map = new MgMap();

and

MgMap map = new MgMap(conn);

???

 

Many thanks for your help.

 

Here the code that works for me. I put some comment:

 

<%

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);
 

 

//WHICH IS THE DIFFERENCE??

//MgMap map = new MgMap(siteConnection);

MgMap map = new MgMap();

map.Open(resourceService, mapName);


 //I'VE TRIED TO IDENTIFY THE RESOURCE IN THIS WAY BUT IT DOESN'T WORK:

//String featureSourceName = "Session:" + sessionId + "//prova_basic/Data/area.FeatureSource";

//MgResourceIdentifier fdo = new MgResourceIdentifier(featureSourceName);
//BUT IN THIS WAY IT WORKS: THERE IS SOME DIFFERENCE??

MgResourceIdentifier fdo = new MgResourceIdentifier("Library://prova_basic/Data/area.FeatureSource");

 

//Specify the property values

MgPropertyCollection properties = new MgPropertyCollection();

MgAgfReaderWriter agfWriter = new MgAgfReaderWriter();

properties.Add(new MgStringProperty("nome", nome));

MgUpdateFeatures updateFeature1 = new MgUpdateFeatures("area", properties, "nome='secondo'");

MgFeatureCommandCollection commands = new MgFeatureCommandCollection();

commands.Add(updateFeature1);

//To commit:

MgLayer layer = (MgLayer)map.GetLayers().GetItem("area");

featureService.UpdateFeatures(fdo, commands, false);

%>

Message 5 of 6
jackie.ng
in reply to: naveen2010

The new MgMap constructor was introduced to enable a whole set of convenience methods without needing to pass the needed MgFeatureService or MgResourceService parameters, as the map will get these services from the MgSiteConnection you pass into the constructor

 

Of course if you invoke the normal MgMap constructor and try to use these methods, there is no MgSiteConnection to grab th needed services from, hence the somewhat cryptic error.

 

See: http://trac.osgeo.org/mapguide/wiki/MapGuideRfc9

 

On the code you just posted: 

 

MgResourceIdentifiers are just like URLs or file paths, the thing they point to must already exist. In the case of your session-based feature source, you need to have either copied or created a feature source at the specified resource id beforehand, otherwise you're just querying a feature source that is not there.

 

- Jackie

Message 6 of 6
studio
in reply to: naveen2010

Ok, thanks for your advice.

At next,

 

Riccardo

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums