[mapguide-users] Listing Active selected feature C#
Knight, Gregory
Gregory.Knight.bra at cityofboston.gov
Tue Jan 23 09:58:07 EST 2007
Sorry for the delay... busy day yesterday.
My C# code goes something like this:
(Note that this example makes use of the listSelected javascript
function. I include that in utilityfunction.aspx. I have included this
code after the C# stuff.)
// get the SESSION id and xml SELECTION
String mgSessionId = GetParameters()["SESSION"];
String xmlSel = GetParameters()["SELECTION"];
// Go!
try
{
// Initialize the web-tier
InitializeWebTier();
MgUserInformation userInfo = new MgUserInformation(mgSessionId);
MgSiteConnection siteConnection = new MgSiteConnection();
siteConnection.Open(userInfo);
// Create a ResourceService object and use it to open the Map
// object from the sessions repository. Create a FeatureService
// object to read the feature information. Create a QueryOptions
// object for creating the list of features.
MgResourceService resourceService =
siteConnection.CreateService(MgServiceType.ResourceService) as
MgResourceService;
MgFeatureService featureService =
siteConnection.CreateService(MgServiceType.FeatureService) as
MgFeatureService;
MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions();
MgMap map = new MgMap();
map.Open(resourceService, "Zoning");
// Create the selection object by retrieving the current
// selection from the map.
MgSelection selection = new MgSelection(map, xmlSel);
MgReadOnlyLayerCollection layers = selection.GetLayers();
Int32 layerCount = layers.GetCount();
// Loop through layers
if (layerCount > 0)
{
for (int i = 0; i < layers.GetCount(); i++)
{
// Only check objects on the Parcels layer
MgLayer layer = layers.GetItem(i);
if (layer.GetName() == "Parcels")
{
// Create a filter containing the IDs of the selected
// features on this layer
string layerClassName = layer.GetFeatureClassName();
string selectionString = selection.GenerateFilter(layer,
layerClassName);
// Get the feature resource for the selected layer
string layerFeatureID = layer.GetFeatureSourceId();
MgResourceIdentifier layerFeatureResource = new
MgResourceIdentifier(layerFeatureID);
// Apply the filter to the feature resource for the
// selected layer. This returns an MgFeatureReader
// of all the selected features.
queryOptions.SetFilter(selectionString);
MgFeatureReader featureReader =
featureService.SelectFeatures(layerFeatureResource, layerClassName,
queryOptions);
// Process each item in the MgFeatureReader and display the
some parcel attributes
MgAgfReaderWriter geometryReaderWriter = new
MgAgfReaderWriter();
while (featureReader.ReadNext())
{
string pid_long =
featureReader.GetString("PID_LONG");
string st_num = featureReader.GetString("ST_NUM");
string st_name = featureReader.GetString("ST_NAME");
string st_sfx = featureReader.GetString("ST_SFX");
string zipcode = featureReader.GetString("ZIPCODE");
// Pull geometry for spatial query
MgByteReader byteReader =
featureReader.GetGeometry("Geometry");
MgGeometry geometry =
geometryReaderWriter.Read(byteReader);
MgPoint point = geometry.GetCentroid();
double x = point.GetCoordinate().GetX();
double y = point.GetCoordinate().GetY();
Response.Write("<tr><td colspan=2
class=\"SubTitle\">Parcel</td></tr>");
Response.Write("<tr><td class=\"InfoText\">Parcel
ID</td><td class=\"InfoText\">" + pid_long + "</td></tr>");
Response.Write("<tr><td
class=\"InfoText\">Address</td><td class=\"InfoText\">" + st_num + " " +
st_name + " " + st_sfx + "</td></tr>");
Response.Write("<tr><td
class=\"InfoText\">Zip</td><td class=\"InfoText\">" + zipcode +
"</td></tr>");
// Intersect with the Zoning District Layer
// to get the District Name
MgResourceIdentifier zlayerFeatureResource = new
MgResourceIdentifier("Library://BOS/Data/Zoning_Districts.FeatureSource"
);
MgFeatureQueryOptions zqueryOptions = new
MgFeatureQueryOptions();
zqueryOptions.SetSpatialFilter("Geometry", geometry,
4);
MgAgfReaderWriter zgeometryReaderWriter = new
MgAgfReaderWriter();
MgFeatureReader zfeatureReader =
featureService.SelectFeatures(zlayerFeatureResource, "Zoning_Districts",
zqueryOptions);
while (zfeatureReader.ReadNext())
{
string zDistrict =
zfeatureReader.GetString("DISTRICT");
Response.Write("<tr><td
class=\"InfoText\">District</td><td class=\"InfoText\">" +
zDistrict.ToUpper() + "</td></tr>");
}
zfeatureReader.Close();
// Intersect with the Zoning SubDistrict Layer
// to get the Base Zoning
MgResourceIdentifier zzlayerFeatureResource = new
MgResourceIdentifier("Library://BOS/Data/Zoning_SubDistricts.FeatureSour
ce");
MgFeatureQueryOptions zzqueryOptions = new
MgFeatureQueryOptions();
zzqueryOptions.SetSpatialFilter("Geometry",
geometry, 4);
MgAgfReaderWriter zzgeometryReaderWriter = new
MgAgfReaderWriter();
MgFeatureReader zzfeatureReader =
featureService.SelectFeatures(zzlayerFeatureResource,
"Zoning_SubDistricts", zzqueryOptions);
while (zzfeatureReader.ReadNext())
{
string zzZone =
zzfeatureReader.GetString("ZONE_");
double zzFAR = zzfeatureReader.GetDouble("FAR");
Response.Write("<tr><td
class=\"InfoText\">Zone</td><td class=\"InfoText\">" + zzZone +
"</td></tr>");
Response.Write("<tr><td class=\"InfoText\">Zone
FAR</td><td class=\"InfoText\">" + zzFAR + "</td></tr>");
}
zzfeatureReader.Close();
}
}
}
}
// listSelected javascript function - include somewhere in
utilityfunctions.aspx
<script language="javascript">
function listSelected()
{
xmlSel = ViewerFrame.mapFrame.GetSelectionXML();
params = new Array("SESSION", ViewerFrame.mapFrame.GetSessionId(),
"SELECTION", xmlSel);
ViewerFrame.formFrame.Submit("../brazoning/getzoningtask.aspx",
params, "taskPaneFrame");
}
</script>
________________________________
From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Andy
Morsell
Sent: Sunday, January 21, 2007 2:15 PM
To: mapguide-users at lists.osgeo.org
Subject: RE: [mapguide-users] Listing Active selected feature C#
Greg,
Would it be possible for you to post the example to the group? The list
should accept plain text file attachments or you could paste it into the
message body.
Andy
________________________________
From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Knight,
Gregory
Sent: Sunday, January 21, 2007 10:43 AM
To: Nimrod Cnaan; mapguide-users at lists.osgeo.org
Subject: RE: [mapguide-users] Listing Active selected feature C#
I have a C# example where I am doing exactly this. I can send you the
page via separate means if you are interested.
Greg
________________________________
From: mapguide-users-bounces at lists.osgeo.org on behalf of Nimrod Cnaan
Sent: Sat 1/20/2007 9:13 AM
To: mapguide-users at lists.osgeo.org
Subject: [mapguide-users] Listing Active selected feature C#
I am attempting to get the list of selected parcels by using "Invoke
URL"
command, passing "$Current Selection" to my "listdwfparcels.aspx" page,
through the key & value pair.
I don't know what I'm doing wrong, getting unclassified exception
"MgSelection.FromXml" . . .
Checking the value of my mgkey content "$Current Selection" returns:
%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%0A%3CFeat
ureSet%3E%0A%3CLayer%20id%3D%22d6a8101a-ffff-ffff-8003-000000000038%22%3
E%0A%3CClass%20id%3D%22Default%3AHelkot%22%3E%0A%3CID%3ETAAAAA%3D%3D%3C%
2FID%3E%0A%3CID%3EVwAAAA%3D%3D%3C%2FID%3E%0A%3CID%3EVgAAAA%3D%3D%3C%2FID
%3E%0A%3C%2FClass%3E%0A%3C%2FLayer%3E%0A%3C%2FFeatureSet%3E%0A
Here is portion of the code that I'm using -
String mgSessionId = GetParameters()["SESSION"];
String mgSelection = GetParameters()["mgkey"];
MgResourceIdentifier layerFeatureResource;
MgReadOnlyLayerCollection layers;
MgSelection selection;
MgLayer layer;
string layerClassName;
string selectionString;
string layerFeatureId;
try
{
InitializeWebTier();
MgUserInformation userInfo = new MgUserInformation(mgSessionId);
MgSiteConnection siteConnection = new MgSiteConnection();
siteConnection.Open(userInfo);
MgResourceService resourceService =
siteConnection.CreateService(MgServiceType.ResourceService) as
MgResourceService;
MgFeatureService featureService =
siteConnection.CreateService(MgServiceType.FeatureService) as
MgFeatureService;
MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions();
MgMap map = new MgMap();
map.Open(resourceService, "HaifaMap");
if (GetParameters()["SESSION"] != "")
{
selection = new MgSelection(map, mgSelection);
<<<<< MY ERROR >>>>>
An unclassified exception occurred.An unclassified exception occurred.
Exception occurred in method MgSelection.FromXml at line 158 in file
c:\build_tux_area\mgdev_opensource\common\service\maplayer\Selection.cpp
Nimrod Cnaan - GIS Senior Programmer
Haifa Municipality, Israel
Phon:972525355483
--
View this message in context:
http://www.nabble.com/Listing-Active-selected-feature-C--tf3045397s16610
.html#a8465318
Sent from the MapGuide Users mailing list archive at Nabble.com.
_______________________________________________
mapguide-users mailing list
mapguide-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users
________________________________
The substance of this message, including any attachments, may be
confidential, legally
privileged and/or exempt from disclosure pursuant to Massachusetts
law. It is intended
solely for the addressee. If you received this in error, please
contact the sender and
delete the material from any computer.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20070123/9ea010b8/attachment-0001.html
More information about the mapguide-users
mailing list