[mapguide-users] Add Point to Existing Layer
Francisco J Rojas D
francisco.rojas at dasoft.com.mx
Mon Feb 4 12:28:03 EST 2008
Hi There,
You can change the ReadOnly attribute by MapAgent index.html page or
programmatically
a) Changing by MapAgent web page.
Go to http://servername:port/mapguide[2008]/mapagent/index.html
Go to GetResourceContent Link, and perform a query using the ResourceID like
Library://Samples/Sheboygan/Data/Parcels.FeatureSource
You will get an XML file like this.
OSGeo.SDF
File
%MG_DATA_FILE_PATH%Road.sdf
ReadOnly
TRUE
You will see a tag if that tag value is TRUE change you must save the XML
file as ParcelsContent.XML, then modify with Notepad changing the TRUE value
to FALSE.
Then go to http://servername:port/mapguide[2008]/mapagent/index.html, go to
SetResource, and provide the ResourceID and the Content XML File by upload
your modified ParcelsContent.XML, for the HEADER field leave it empty, click
on submit and the SDF file will be read/write now.
b) Changing Programmatically
Use the next routines and examples :
// This routine makes a resource writable
private void set_ResourceWriteAble(MgResourceIdentifier resoureId,
MgResourceService resourceService)
{//by knife114
//-----------------------------------------------------------------------------
String buffer;
MgByteReader reader = resourceService.GetResourceContent(resoureId);
buffer = reader.ToString();
if (buffer.Contains("TRUE"))
{
buffer = buffer.Replace("TRUE", "FALSE");
Byte[] buf_Byte = System.Text.Encoding.Default.GetBytes(buffer);
MgByteSource byteSource = new MgByteSource(buf_Byte,
buf_Byte.Length);
resourceService.SetResource(resoureId, byteSource.GetReader(),
null);
}
//-----------------------------------------------------------------------------
}
This is an example code using the code above:
MgGeometryFactory geoFac = new MgGeometryFactory();
MgLinearRingCollection LinearRingCollection = new
MgLinearRingCollection();
MgCoordinateCollection CoordinateCollection = new
MgCoordinateCollection();
String[] coods = this.TextBox1.Text.Split(',');
for (int i = 1; i <= Convert.ToInt16(coods[0])*2 ; i+=2)
{
double x = Convert.ToDouble(coods[i]);
double y = Convert.ToDouble(coods[i+1]);
MgCoordinate coordinate = geoFac.CreateCoordinateXY(x, y);
CoordinateCollection.Add(coordinate);
//MgPoint point = new
MgGeometryFactory().CreatePoint(coordinate);
}
MgLinearRing LinearRing =
geoFac.CreateLinearRing(CoordinateCollection);
CoordinateCollection.Clear();
LinearRingCollection.Add(LinearRing);
MgPolygon Polygon = geoFac.CreatePolygon(LinearRing, null);
//propertyCol.Add(new MgInt32Property("Autogenerated_SDF_ID",
11));
propertyCol.Add(new MgStringProperty("Name", "it's me"));
propertyCol.Add(new MgInt32Property("Key", 11));
propertyCol.Add(new MgStringProperty("Url", "me,too"));
//Polygon.
propertyCol.Add(new MgGeometryProperty("Data",
geometryReaderWriter.Write(Polygon)));
ftrCmdCol.Add(new MgInsertFeatures(lyrClass, propertyCol));
set_ResourceWriteAble(resoureId, resourceService); // set sdf
readonly=false
if (ftrCmdCol.Count >= 1)
{
ReleaseReader(ftrService.UpdateFeatures(resoureId,
ftrCmdCol, false), ftrCmdCol);
layerToSave.ForceRefresh();
map.Save(resourceService);
}
Regards
Francisco J Rojas D
Pascal Coulon wrote:
>
> Hi There,
>
> When creating a layer (SDF) in Studio. It is created in ReadOnly mode. You
> need to enable read/write by using the mapagent. Let me know if you need
> any further details.
>
> Regards,
>
> pascal
>
>
>
> Jackie Ng wrote:
>>
>> Open two browser windows/tabs, one to your web application that adds the
>> points. Another to the schemareport page (usually at
>> http://servername:port/mapguide/schemareport/main.php )
>>
>> Run your add point routine, then check if the schemareport for that
>> feature source has included the point you have just added.
>>
>> If the point is there, then i suspect it is something to do with the
>> layer that's based off of the feature source.
>>
>> Otherwise, your php script is clearly failing to insert the new point
>> feature.
>>
>> - Jackie
>>
>>
>> gaku wrote:
>>>
>>> Yes,I have created site resources by use Administrator username.
>>>
>>>
>>>
>>> -gaku
>>>
>>>
>>> Jackie Ng wrote:
>>>>
>>>> Oh I see, I thought you were adding points to a session-based feature
>>>> source.
>>>>
>>>> In that case, did you create a mapguide session via a username that has
>>>> permissions to modify site resources?
>>>>
>>>> - Jackie
>>>>
>>>>
>>>> gaku wrote:
>>>>>
>>>>> Yes, I have created the feature source by using Mapguide Studio.
>>>>>
>>>>>
>>>>> Jackie Ng wrote:
>>>>>>
>>>>>> Have you actually created the feature source pointed to by
>>>>>> $featureSourceId ? (ie. Have you called
>>>>>> $featureService->CreateFeatureSource() ?)
>>>>>>
>>>>>> - Jackie
>>>>>>
>>>>>>
>>>>>> gaku wrote:
>>>>>>>
>>>>>>> Hi all
>>>>>>>
>>>>>>> I'm trying to let the user insert a point feature in PHP along with
>>>>>>> some attributes. The feature source is an SDF file and the code was
>>>>>>> translated/modified from the PHP example (draw_line). The user can
>>>>>>> get the X, Y coordinates from another button (works fine).
>>>>>>>
>>>>>>> Everything compiles fine and execute well but no feature is added to
>>>>>>> the feature source. I tried with a converted SDF feature source
>>>>>>> (didnt change a thing).
>>>>>>>
>>>>>>> Did I miss something ? Did I do something wrong :)
>>>>>>>
>>>>>>> Any help would be appreciated
>>>>>>>
>>>>>>> here's the code :
>>>>>>>
>>>>>>> ------------------------------------------------------------
>>>>>>>
>>>>>>> try
>>>>>>> {
>>>>>>> MgInitializeWebTier($webconfigFilePath);
>>>>>>>
>>>>>>> // Get the session information passed from the viewer.
>>>>>>> $sessionId = ($_SERVER['REQUEST_METHOD'] ==
>>>>>>> "POST")?$_POST['SESSION']: $_GET['SESSION'];
>>>>>>>
>>>>>>> // Get the user information using the session id,
>>>>>>> // and set up a connection to the site server.
>>>>>>> $userInfo = new MgUserInformation($sessionId);
>>>>>>> $siteConnection = new MgSiteConnection();
>>>>>>> $siteConnection->Open($userInfo);
>>>>>>>
>>>>>>>
>>>>>>> $resourceService =
>>>>>>> $siteConnection->CreateService(MgServiceType::ResourceService);
>>>>>>> $featureService =
>>>>>>> $siteConnection->CreateService(MgServiceType::FeatureService);
>>>>>>> $featureSourceId = new
>>>>>>> MgResourceIdentifier('Library://Sample/Data/020101Markup.FeatureSource');
>>>>>>>
>>>>>>>
>>>>>>> $map = new MgMap();
>>>>>>> $map->Open($resourceService, $mgMapName);
>>>>>>>
>>>>>>> //$geometryFactory = new MgGeometryFactory();
>>>>>>> $wktReaderWriter = new MgWktReaderWriter();
>>>>>>> $agfReaderWriter = new MgAgfReaderWriter();
>>>>>>>
>>>>>>> $geo = $wktReaderWrite->Read("POINT XY ( $x, $y )");
>>>>>>>
>>>>>>> $geoByteReader = new MgByteReader();
>>>>>>> $geoByteReader = $agfReaderWriter->Write($geo);
>>>>>>>
>>>>>>> $idid = 500;
>>>>>>>
>>>>>>> $propertyValues = new MgPropertyCollection();
>>>>>>> $propertyValues->Add(new MgInt32Property("ID", $idid ));
>>>>>>> $propertyValues->Add(new MgStringProperty(name, 'test'));
>>>>>>> $propertyValues->Add(new MgGeometryProperty('Geometry',
>>>>>>> $geoByteReader));
>>>>>>>
>>>>>>> $commands = new MgFeatureCommandCollection();
>>>>>>> $commands->Add(new MgInsertFeatures('020101Markup',
>>>>>>> $propertyValues));
>>>>>>> $featureService->UpdateFeatures($featureSourceId, $commands,
>>>>>>> false);
>>>>>>>
>>>>>>>
>>>>>>> }
>>>>>>> catch (MgException $e)
>>>>>>> {
>>>>>>> $errorMsg = $e->GetMessage();
>>>>>>> $errorDetail = $e->GetDetails();
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> -------------------------------end of code -------------
>>>>>>>
>>>>>>> --Thanks,
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Add-Point-to-Existing-Layer-tp15136337s16610p15269590.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20080204/ab086b83/attachment.html
More information about the mapguide-users
mailing list