Esempio n. 1
0
        internal RedlineLayer[] GetAvailableLayers(MgMapBase map)
        {
            var fsId = GetRegistryFeatureSource();
            MgLayerCollection   mapLayers = map.GetLayers();
            List <RedlineLayer> layers    = new List <RedlineLayer>();
            MgFeatureReader     reader    = null;

            try
            {
                reader = _featSvc.SelectFeatures(fsId, "Default:MarkupRegistry", null);
                while (reader.ReadNext())
                {
                    layers.Add(new RedlineLayer(reader.GetString("Name"),
                                                reader.GetString("ResourceId"),
                                                reader.GetString("LayerDefinition"),
                                                reader.GetInt32("GeometryTypes"),
                                                (RedlineStylizationType)reader.GetInt32("StyleType")));
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return(layers.ToArray());
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgFeatureService      featSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService);
                MgFeatureQueryOptions query   = new MgFeatureQueryOptions();
                string[] propNames            = txtProps.Text.Split(',');
                foreach (var p in propNames)
                {
                    if (string.IsNullOrEmpty(p))
                    {
                        continue;
                    }

                    query.AddFeatureProperty(p);
                }

                foreach (Pair p in lstComputed.Items)
                {
                    query.AddComputedProperty(p.Name, p.Expr);
                }

                if (!string.IsNullOrEmpty(txtFilter.Text.Trim()))
                {
                    query.SetFilter(txtFilter.Text.Trim());
                }

                MgResourceIdentifier fsId = new MgResourceIdentifier(txtFeatureSource.Text);

                MgFeatureReader reader = featSvc.SelectFeatures(fsId, txtClass.Text, query);
                new ReaderResponseDialog(reader).ShowDialog();
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
        }
Esempio n. 3
0
        public IEnumerable <RedlineObject> GetAllFeatures()
        {
            MgMapBase         map          = _viewer.GetMap();
            MgLayerCollection layers       = map.GetLayers();
            MgLayerBase       redlineLayer = layers.GetItem(_layer.SystemName);

            MgResourceIdentifier resId  = new MgResourceIdentifier(redlineLayer.GetFeatureSourceId());
            MgFeatureReader      reader = null;

            try
            {
                reader = _featSvc.SelectFeatures(resId, RedlineSchemaFactory.CLASS_NAME, null);

                //HACK: Another leaky abstraction. SHP will always choose FeatId, so once again
                //use the class definition to determine the identity property name
                MgClassDefinition cls = reader.GetClassDefinition();
                MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();
                MgPropertyDefinition           keyProp = idProps.GetItem(0);
                string idName = keyProp.GetName();

                while (reader.ReadNext())
                {
                    int    id   = reader.GetInt32(idName);
                    string text = reader.IsNull(RedlineSchemaFactory.TEXT_NAME) ? string.Empty : reader.GetString(RedlineSchemaFactory.TEXT_NAME);

                    yield return(new RedlineObject(id, text));
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
Esempio n. 4
0
    //---------------------------------------------------------------------------------------
    //
    //        ���ܣ������ѯ���
    //
    //         ���ߣ�
    //
    //         ���ڣ� 2007.5.23
    //        
    //         �޸���ʷ����
    //        
    //---------------------------------------------------------------------------------------
    public void OutputSelectionInHTML(MgSelection selection, MgFeatureService featureService)
    {
        MgReadOnlyLayerCollection layers = selection.GetLayers();
        String outString = null;

        if (layers != null)
        {
            for (int i = 0; i < layers.GetCount(); i++)
            {
                MgLayer layer = layers.GetItem(i);
                if ((layer != null) && (layer.GetName() == "Parcels"))
                {
                    String layerClassName = layer.GetFeatureClassName();
                    selectString = selection.GenerateFilter(layer, layerClassName);

                    String layerFeatureIdString = layer.GetFeatureSourceId();
                    MgResourceIdentifier layerResId = new MgResourceIdentifier(layerFeatureIdString);

                    MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions();
                    queryOptions.SetFilter(selectString);
                    MgFeatureReader featReader = featureService.SelectFeatures(layerResId, layerClassName, queryOptions);

                    outString = outString + "<table border=\"1\">\n";

                    double acre = 0;

                    while (featReader.ReadNext())
                    {
                        outString = outString + "<tr>\n";

                        outString = outString + "<td>";
                        outString = outString + featReader.GetString("RNAME");
                        outString = outString + "</td>\n";
                        outString = outString + "<td>";
                        outString = outString + featReader.GetString("RPROPAD");
                        outString = outString + "</td>\n";
                        outString = outString + "<td>";
                        String acreString = featReader.GetString("RACRE");
                        acre = acre + (acreString == "" ? 0 : Convert.ToDouble(acreString));
                        outString = outString + acreString;
                        outString = outString + "</tr>\n";

                    }
                    outString = outString + "</table>\n";

            featReader.Close();
                }
            }
        }
        selectionResult = outString;
    }
    MgGeometry MultiGeometryFromSelection(MgFeatureService featureSrvc, MgMap map, String selText)
    {
        MgSelection sel = new MgSelection(map);
        sel.FromXml(selText);
        MgReadOnlyLayerCollection selLayers = sel.GetLayers();
        if (selLayers == null)
            return null;
        MgGeometryCollection geomColl = new MgGeometryCollection();
        MgAgfReaderWriter agfRW = new MgAgfReaderWriter();
        bool polyOnly = true;

        for (int i = 0; i < selLayers.GetCount(); i++)
        {
            MgLayer layer = (MgLayer)selLayers.GetItem(i);

            // TODO:  How to get selectionSize?
            //int selectionSize = 20;
            string filter = sel.GenerateFilter(layer, layer.GetFeatureClassName());

            if (filter == "")
                continue;

            MgFeatureQueryOptions query = new MgFeatureQueryOptions();
            query.SetFilter(filter);
            MgResourceIdentifier featureSource = new MgResourceIdentifier(layer.GetFeatureSourceId());
            MgFeatureReader features = featureSrvc.SelectFeatures(featureSource, layer.GetFeatureClassName(), query);

            if (features != null)
            {
                MgClassDefinition classDef = features.GetClassDefinition();
                String geomPropName = classDef.GetDefaultGeometryPropertyName();
                int j = 0;
                //bool isPoly = true;
                while (features.ReadNext())
                {
                    MgByteReader geomReader = features.GetGeometry(geomPropName);
                    MgGeometry geom = agfRW.Read(geomReader);
                    if (j++ == 0)
                    {
                        int type = geom.GetGeometryType();
                        if (type == MgGeometryType.MultiPolygon || type == MgGeometryType.CurvePolygon || type == MgGeometryType.MultiCurvePolygon)
                        {
                            //isPoly = false;
                            polyOnly = false;
                        }
                        else if (type != MgGeometryType.Polygon)
                        {
                            break;
                        }
                    }
                    geomColl.Add(geom);
                }
                features.Close();
                features.Dispose();
            }

        }

        if (geomColl.GetCount() == 0)
        {
            return null;
        }

        MgGeometryFactory gf = new MgGeometryFactory();
        if (polyOnly)
        {
            MgPolygonCollection polyColl = new MgPolygonCollection();
            for (int j = 0; j < geomColl.GetCount(); j++)
            {
                polyColl.Add((MgPolygon)geomColl.GetItem(j));
            }
            return gf.CreateMultiPolygon(polyColl);
        }
        else
        {
            return gf.CreateMultiGeometry(geomColl);
        }
    }
Esempio n. 6
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            btnCreate.Enabled = false;
            try
            {
                var layerName = txtBufferLayer.Text.Trim();
                if (string.IsNullOrEmpty(layerName))
                {
                    MessageBox.Show(Strings.MsgEnterNameForLayer);
                    return;
                }

                if (lstLayers.SelectedItems.Count == 0)
                {
                    MessageBox.Show(Strings.MsgIncludeLayersToBuffer);
                    return;
                }

                var map      = _viewer.GetMap();
                var layers   = map.GetLayers();
                var provider = _viewer.GetProvider();

                //From here, it's the same logic as buffer.aspx in .net MapGuide AJAX viewer
                MgResourceIdentifier fsId  = new MgResourceIdentifier("Session:" + _sessionId + "//" + txtBufferLayer.Text + "_Buffer.FeatureSource");   //NOXLATE
                MgResourceIdentifier ldfId = new MgResourceIdentifier("Session:" + _sessionId + "//" + txtBufferLayer.Text + "_Buffer.LayerDefinition"); //NOXLATE

                MgLayerBase layer      = Util.FindLayer(layers, txtBufferLayer.Text);
                string[]    layerNames = GetLayerNames();

                double          distance = Convert.ToDouble(numBufferDistance.Value);
                MeasurementUnit bUnits   = (MeasurementUnit)cmbUnits.SelectedItem;
                switch (bUnits)
                {
                case MeasurementUnit.Feet:
                    distance *= 0.30480;
                    break;

                case MeasurementUnit.Kilometers:
                    distance *= 1000;
                    break;

                case MeasurementUnit.Miles:
                    distance *= 1609.35;
                    break;
                }

                String             srsDefMap   = Util.GetMapSrs(map);
                MgCoordinateSystem srsMap      = provider.GetMapCoordinateSystem();
                string             mapSrsUnits = "";
                bool arbitraryMapSrs           = (srsMap.GetType() == MgCoordinateSystemType.Arbitrary);
                if (arbitraryMapSrs)
                {
                    mapSrsUnits = srsMap.GetUnits();
                }

                String xtrans     = String.Format("{0:x2}", ((int)(255 * Convert.ToInt32(numFillTransparency.Value) / 100))); //NOXLATE
                var    lineColor  = Util.ToHtmlColor(pnlBorderColor.BackColor);
                var    foreColor  = Util.ToHtmlColor(pnlFillColor.BackColor);
                var    backColor  = Util.ToHtmlColor(pnlFillBackColor.BackColor);
                String layerTempl = string.Format(Properties.Resources.AreaLayerDef,
                                                  fsId.ToString(),
                                                  "BufferSchema:Buffer", //NOXLATE
                                                  "GEOM",                //NOXLATE
                                                  cmbFillPattern.SelectedItem,
                                                  xtrans + foreColor,
                                                  ((0 != 1 /*transparent*/) ? "ff" : "00") + backColor, //NOXLATE
                                                  cmbBorderPattern.SelectedItem,
                                                  numLineThickness.Value.ToString(NumberFormatInfo.InvariantInfo),
                                                  lineColor
                                                  );
                byte[]       bytes           = Encoding.UTF8.GetBytes(layerTempl);
                MgByteSource src             = new MgByteSource(bytes, bytes.Length);
                MgByteReader layerDefContent = src.GetReader();
                _resSvc.SetResource(ldfId, layerDefContent, null);

                bool newBuffer = false;
                if (layer == null)
                {
                    newBuffer = true;

                    //Targetting a new layer. create a data source for it
                    //
                    MgClassDefinition classDef = new MgClassDefinition();

                    classDef.SetName("Buffer");                                //NOXLATE
                    classDef.SetDescription("Feature class for buffer layer"); //NOXLATE
                    classDef.SetDefaultGeometryPropertyName("GEOM");           //NOXLATE

                    //Set KEY property
                    MgDataPropertyDefinition prop = new MgDataPropertyDefinition("KEY"); //NOXLATE
                    prop.SetDataType(MgPropertyType.Int32);
                    prop.SetAutoGeneration(true);
                    prop.SetReadOnly(true);
                    classDef.GetIdentityProperties().Add(prop);
                    classDef.GetProperties().Add(prop);

                    //Set ID property. Hold this segment ID
                    prop = new MgDataPropertyDefinition("ID"); //NOXLATE
                    prop.SetDataType(MgPropertyType.Int32);
                    classDef.GetProperties().Add(prop);

                    //Set geometry property
                    MgGeometricPropertyDefinition geomProp = new MgGeometricPropertyDefinition("GEOM"); //NOXLATE
                    //prop.SetGeometryTypes(MgFeatureGeometricType.mfgtSurface); //TODO use the constant when exposed
                    geomProp.SetGeometryTypes(4);
                    classDef.GetProperties().Add(geomProp);

                    //Create the schema
                    MgFeatureSchema schema = new MgFeatureSchema("BufferSchema", "Temporary buffer schema"); //NOXLATE
                    schema.GetClasses().Add(classDef);

                    //finally, creation of the feature source
                    MgFileFeatureSourceParams sdfParams = new MgFileFeatureSourceParams("OSGeo.SDF", "LatLong", map.GetMapSRS(), schema); //NOXLATE
                    _featSvc.CreateFeatureSource(fsId, sdfParams);

                    //Add layer to map
                    layer = provider.CreateLayer(ldfId);
                    layer.SetName(txtBufferLayer.Text);
                    layer.SetLegendLabel(txtBufferLayer.Text);
                    layer.SetDisplayInLegend(true);
                    layer.SetSelectable(true);
                    layers.Insert(0, layer);
                }
                else
                {
                    //data source already exist. clear its content
                    //
                    Util.ClearDataSource(_featSvc, fsId, "BufferSchema:Buffer"); //NOXLATE
                }

                var sel       = _viewer.GetSelection();
                var selLayers = sel.GetLayers();

                MgAgfReaderWriter    agfRW            = new MgAgfReaderWriter();
                MgGeometryCollection bufferGeometries = new MgGeometryCollection();
                MgGeometry           geomBuffer;

                MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
                int featId = 0;

                MgBatchPropertyCollection propCollection = new MgBatchPropertyCollection();

                int excludedLayers                   = 0;
                MgCoordinateSystem   srsDs           = null;
                MgGeometryCollection inputGeometries = new MgGeometryCollection();

                int bufferFeatures = 0;
                for (int li = 0; li < selLayers.GetCount(); li++)
                {
                    MgLayerBase selLayer     = selLayers.GetItem(li);
                    bool        inputLayer   = false;
                    String      selLayerName = selLayer.GetName();
                    for (int il = 0; il < layerNames.Length; il++)
                    {
                        if (layerNames[il].Equals(selLayerName))
                        {
                            inputLayer = true;
                            break;
                        }
                    }
                    if (inputLayer == false)
                    {
                        continue;
                    }

                    // get the data source SRS
                    //
                    MgResourceIdentifier   featSourceId = new MgResourceIdentifier(selLayer.GetFeatureSourceId());
                    MgSpatialContextReader ctxs         = _featSvc.GetSpatialContexts(featSourceId, false);
                    String srsDefDs = string.Empty;
                    if (ctxs != null && ctxs.ReadNext())
                    {
                        srsDefDs = ctxs.GetCoordinateSystemWkt();
                    }

                    if (srsDefDs == null || srsDefDs.Length == 0)
                    {
                        excludedLayers++;
                        continue;
                    }

                    var srsFactory = new MgCoordinateSystemFactory();
                    srsDs = srsFactory.Create(srsDefDs);
                    bool   arbitraryDsSrs = (srsDs.GetType() == MgCoordinateSystemType.Arbitrary);
                    String dsSrsUnits     = string.Empty;

                    if (arbitraryDsSrs)
                    {
                        dsSrsUnits = srsDs.GetUnits();
                    }

                    // exclude layer if:
                    //  the map is non-arbitrary and the layer is arbitrary or vice-versa
                    //     or
                    //  layer and map are both arbitrary but have different units
                    //
                    if ((arbitraryDsSrs != arbitraryMapSrs) || (arbitraryDsSrs && (dsSrsUnits != mapSrsUnits)))
                    {
                        excludedLayers++;
                        continue;
                    }

                    // calculate distance in the data source SRS units
                    //
                    double dist = srsDs.ConvertMetersToCoordinateSystemUnits(distance);

                    // calculate great circle unless data source srs is arbitrary
                    MgCoordinateSystemMeasure measure;
                    if (!arbitraryDsSrs)
                    {
                        measure = srsDs.GetMeasure();
                    }
                    else
                    {
                        measure = null;
                    }

                    // create a SRS transformer if necessary
                    MgCoordinateSystemTransform srsXform;
                    if (!srsDefDs.Equals(srsDefMap))
                    {
                        srsXform = srsFactory.GetTransform(srsDs, srsMap);
                    }
                    else
                    {
                        srsXform = null;
                    }

                    String featureClassName = selLayer.GetFeatureClassName();
                    String filter           = sel.GenerateFilter(selLayer, featureClassName);
                    if (filter == null || filter.Length == 0)
                    {
                        continue;
                    }

                    MgFeatureQueryOptions query = new MgFeatureQueryOptions();
                    query.SetFilter(filter);

                    MgResourceIdentifier featureSource = new MgResourceIdentifier(selLayer.GetFeatureSourceId());

                    MgFeatureReader features = _featSvc.SelectFeatures(featureSource, featureClassName, query);

                    if (features.ReadNext())
                    {
                        MgClassDefinition classDef     = features.GetClassDefinition();
                        String            geomPropName = classDef.GetDefaultGeometryPropertyName();

                        do
                        {
                            MgByteReader geomReader = features.GetGeometry(geomPropName);
                            MgGeometry   geom       = agfRW.Read(geomReader);

                            if (!chkMergeBuffers.Checked)
                            {
                                geomBuffer = geom.Buffer(dist, measure);
                                if (geomBuffer != null)
                                {
                                    if (srsXform != null)
                                    {
                                        geomBuffer = (MgGeometry)geomBuffer.Transform(srsXform);
                                    }
                                    Util.AddFeatureToCollection(propCollection, agfRW, featId++, geomBuffer);
                                    bufferFeatures++;
                                }
                            }
                            else
                            {
                                if (srsXform != null)
                                {
                                    geom = (MgGeometry)geom.Transform(srsXform);
                                }
                                inputGeometries.Add(geom);
                            }
                        }while (features.ReadNext());

                        features.Close();
                    }
                }

                if (chkMergeBuffers.Checked)
                {
                    if (inputGeometries.GetCount() > 0)
                    {
                        double dist = srsMap.ConvertMetersToCoordinateSystemUnits(distance);
                        MgCoordinateSystemMeasure measure;
                        if (!arbitraryMapSrs)
                        {
                            measure = srsMap.GetMeasure();
                        }
                        else
                        {
                            measure = null;
                        }

                        MgGeometryFactory geomFactory = new MgGeometryFactory();
                        geomBuffer = geomFactory.CreateMultiGeometry(inputGeometries).Buffer(dist, measure);
                        if (geomBuffer != null)
                        {
                            Util.AddFeatureToCollection(propCollection, agfRW, featId, geomBuffer);
                            bufferFeatures = 1;
                        }
                    }
                }

                if (propCollection.GetCount() > 0)
                {
                    commands.Add(new MgInsertFeatures("BufferSchema:Buffer", propCollection)); //NOXLATE

                    //Insert the features in the temporary data source
                    //
                    Util.ReleaseReader(_featSvc.UpdateFeatures(fsId, commands, false), commands);
                }

                // Save the new map state
                //
                layer.ForceRefresh();
                _viewer.RefreshMap();

                //build report message
                if (newBuffer)
                {
                    MessageBox.Show(string.Format(Strings.MsgBufferLayerCreated, txtBufferLayer.Text));
                }
                else
                {
                    MessageBox.Show(string.Format(Strings.MsgBufferLayerUpdated, txtBufferLayer.Text));
                }
            }
            finally
            {
                btnCreate.Enabled = true;
            }
        }
Esempio n. 7
0
    MgGeometry MultiGeometryFromSelection(MgFeatureService featureSrvc, MgMap map, String selText)
    {
        MgSelection sel = new MgSelection(map);

        sel.FromXml(selText);
        MgReadOnlyLayerCollection selLayers = sel.GetLayers();

        if (selLayers == null)
        {
            return(null);
        }
        MgGeometryCollection geomColl = new MgGeometryCollection();
        MgAgfReaderWriter    agfRW    = new MgAgfReaderWriter();
        bool polyOnly = true;

        for (int i = 0; i < selLayers.GetCount(); i++)
        {
            MgLayer layer = (MgLayer)selLayers.GetItem(i);

            // TODO:  How to get selectionSize?
            //int selectionSize = 20;
            string filter = sel.GenerateFilter(layer, layer.GetFeatureClassName());

            if (filter == "")
            {
                continue;
            }

            MgFeatureQueryOptions query = new MgFeatureQueryOptions();
            query.SetFilter(filter);
            MgResourceIdentifier featureSource = new MgResourceIdentifier(layer.GetFeatureSourceId());
            MgFeatureReader      features      = featureSrvc.SelectFeatures(featureSource, layer.GetFeatureClassName(), query);

            if (features != null)
            {
                MgClassDefinition classDef     = features.GetClassDefinition();
                String            geomPropName = classDef.GetDefaultGeometryPropertyName();
                int j = 0;
                //bool isPoly = true;
                while (features.ReadNext())
                {
                    MgByteReader geomReader = features.GetGeometry(geomPropName);
                    MgGeometry   geom       = agfRW.Read(geomReader);
                    if (j++ == 0)
                    {
                        int type = geom.GetGeometryType();
                        if (type == MgGeometryType.MultiPolygon || type == MgGeometryType.CurvePolygon || type == MgGeometryType.MultiCurvePolygon)
                        {
                            //isPoly = false;
                            polyOnly = false;
                        }
                        else if (type != MgGeometryType.Polygon)
                        {
                            break;
                        }
                    }
                    geomColl.Add(geom);
                }
                features.Close();
                features.Dispose();
            }
        }

        if (geomColl.GetCount() == 0)
        {
            return(null);
        }

        MgGeometryFactory gf = new MgGeometryFactory();

        if (polyOnly)
        {
            MgPolygonCollection polyColl = new MgPolygonCollection();
            for (int j = 0; j < geomColl.GetCount(); j++)
            {
                polyColl.Add((MgPolygon)geomColl.GetItem(j));
            }
            return(gf.CreateMultiPolygon(polyColl));
        }
        else
        {
            return(gf.CreateMultiGeometry(geomColl));
        }
    }
Esempio n. 8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string sessionId = GetRequestParameters(Request)["SESSION"];
            string mapName   = GetRequestParameters(Request)["MAPNAME"];
            string locale    = GetRequestParameters(Request)["LOCALE"];

            if (string.IsNullOrEmpty(sessionId))
            {
                Response.Clear();
                Response.End();
                return;
            }

            if (string.IsNullOrEmpty(mapName))
            {
                Response.Clear();
                Response.End();
                return;
            }

            MgResourceService resourceSrvc = GetMgResurceService(sessionId);
            MgFeatureService  featureSrvc  = GetMgFeatureService(sessionId);

            MgMap map = new MgMap();
            map.Open(resourceSrvc, mapName);

            string layernames = GetRequestParameters(Request)["LAYERNAMES"];
            string GEOMETRY   = GetRequestParameters(Request)["GEOMETRY"];
            string selVar     = GetRequestParameters(Request)["SELECTIONVARIANT"];
            string type       = GetRequestParameters(Request)["tp"];
            string inputSel   = GetRequestParameters(Request)["SELECTION"];

            bool hasInputGeom = false;
            if (!string.IsNullOrEmpty(GEOMETRY))
            {
                hasInputGeom = true;
            }

            //selection ima prednost pred podano geometrijo ...
            MgWktReaderWriter wktrw = new MgWktReaderWriter();
            if (!string.IsNullOrEmpty(inputSel))
            {
                MgGeometry inputGeom = MultiGeometryFromSelection(featureSrvc, map, inputSel);
                GEOMETRY = wktrw.Write(inputGeom);
            }

            MgAgfReaderWriter agfRW = new MgAgfReaderWriter();

            int nLayer = 0;
            // pobrišem in zgradim na novo samo tiste, ki imajo zadetke ...
            int           nSloj  = 0;
            string        filter = "";
            StringBuilder sbOut  = new StringBuilder();
            sbOut.Append("<table width=\"100%\" class=\"results\">");
            sbOut.Append("<tr><td class='header'></td><td class='header'>" + "Layer" + "</td><td class='header' align=\"center\">" + "Select" + "</td><td class='header' align=\"center\">" + "Report" + "</td></tr>");

            MgSelection selAll = new MgSelection(map);

            foreach (MgLayer layer in map.GetLayers())
            {
                if (type != "2")
                {
                    if (!layer.IsVisible())
                    {
                        goto nextlay;
                    }
                }

                if (layer.LegendLabel == "")
                {
                    goto nextlay;
                }

                try
                {
                    nLayer++;

                    filter = String.Format("{0} {1} GeomFromText('{2}')", layer.GetFeatureGeometryName(), selVar, GEOMETRY);

                    //preveriti še filter na Layerju. Ker ne gre drugače, je potrebno pogledati v XML
                    MgResourceIdentifier layerDefResId = layer.GetLayerDefinition();
                    MgByteReader         byteReader    = resourceSrvc.GetResourceContent(layerDefResId);

                    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                    String xmlLayerDef         = byteReader.ToString();
                    doc.LoadXml(xmlLayerDef);

                    KALI.MGE.Objects.KALILayerDefinition.LayerDefinition ld = KALI.MGE.Objects.KALILayerDefinition.LayerDefinition.Parse(xmlLayerDef);

                    if (!string.IsNullOrEmpty(ld.VectorLayerDefinition.Filter))
                    {
                        filter += " AND (" + ld.VectorLayerDefinition.Filter + ")";
                    }

                    //query the features
                    MgFeatureQueryOptions opts = new MgFeatureQueryOptions();
                    opts.SetFilter(filter);
                    String featureClassName    = layer.GetFeatureClassName();
                    MgResourceIdentifier srcId = new MgResourceIdentifier(layer.GetFeatureSourceId());

                    MgFeatureReader features = featureSrvc.SelectFeatures(srcId, featureClassName, opts);

                    bool hasResult = features.ReadNext();

                    if (hasResult)
                    {
                        nSloj++;

                        int n = 0;

                        MgClassDefinition classDef = features.GetClassDefinition();

                        MgPropertyDefinitionCollection classDefProps = classDef.GetIdentityProperties();
                        ArrayList idPropNames = new ArrayList(classDefProps.GetCount());
                        for (int j = 0; j < classDefProps.GetCount(); j++)
                        {
                            MgPropertyDefinition idProp = classDefProps.GetItem(j);
                            idPropNames.Add(idProp.GetName());
                        }

                        MgSelection sel = new MgSelection(map);
                        do
                        {
                            // Generate XML to selection this feature
                            MgPropertyCollection idProps = new MgPropertyCollection();
                            foreach (string id in idPropNames)
                            {
                                int idPropType = features.GetPropertyType(id);
                                switch (idPropType)
                                {
                                case MgPropertyType.Int32:
                                    idProps.Add(new MgInt32Property(id, features.GetInt32(id)));
                                    break;

                                case MgPropertyType.String:
                                    idProps.Add(new MgStringProperty(id, features.GetString(id)));
                                    break;

                                case MgPropertyType.Int64:
                                    idProps.Add(new MgInt64Property(id, features.GetInt64(id)));
                                    break;

                                case MgPropertyType.Double:
                                    idProps.Add(new MgDoubleProperty(id, features.GetDouble(id)));
                                    break;

                                case MgPropertyType.Single:
                                    idProps.Add(new MgSingleProperty(id, features.GetSingle(id)));
                                    break;

                                case MgPropertyType.DateTime:
                                    idProps.Add(new MgDateTimeProperty(id, features.GetDateTime(id)));
                                    break;

                                default:
                                    //throw new SearchError(String.Format(MgLocalizer.GetString("SEARCHTYYPENOTSUP", locale), new Object[] { idPropType.ToString() }), searchError);
                                    break;
                                }
                            }

                            sel.AddFeatureIds(layer, featureClassName, idProps);
                            selAll.AddFeatureIds(layer, featureClassName, idProps);

                            n++;

                            //if (n > 1000) break;
                        } while (features.ReadNext());

                        features.Close();
                        features.Dispose();

                        string selText = EscapeForHtml(sel.ToXml());
                        string seljs   = "<div class=\"allLay\" onclick=\"parent.SetSelectionXML('" + selText + "');\"><img width=\"16\" height=\"16\" style=\"border:0\" src=\"images/mActionZoomToSelected.png\"/></div>";
                        string seljs3  = "<div class=\"allLay\" onclick=\"parent.MultiGridShow('" + selText + "');\"><img width=\"16\" height=\"16\" style=\"border:0\" src=\"images/mActionOpenTable.png\"/></div>";

                        string linfo = "<b>" + layer.LegendLabel + "</b><br />" + n.ToString() + " " + "Hits";
                        sbOut.Append("<tr><td class=\"results\">" + nSloj.ToString() + "</td><td class=\"results\">" + linfo + "</td><td align=\"center\" class=\"results\">" + seljs + "</td><td align=\"center\" class=\"results\">" + seljs3 + "</td></tr>");
                    }
                }
                catch (Exception)
                {
                    continue;
                }

nextlay:
                continue;
            }

            sbOut.Append("</table>");

            string selAllText = EscapeForHtml(selAll.ToXml());
            string seljsAll   = "<div class=\"allLay\" onclick=\"parent.SetSelectionXML('" + selAllText + "');\"><img width=\"16\" height=\"16\" style=\"border:0\" src=\"images/mActionZoomToSelected.png\"/>" + "Select All" + "</div>";
            string seljsAll3  = "<div class=\"allLay\" onclick=\"parent.MultiGridShow('" + selAllText + "');\"><img width=\"16\" height=\"16\" style=\"border:0\" src=\"images/mActionOpenTable.png\"/>" + "Report All" + "</div>";

            sbOut.Append(string.Format("<br /><table width=\"100%\" class=\"results\"><tr><td class=\"results\">{0}</td><td class=\"results\">{1}</td></tr></table>", seljsAll, seljsAll3));


            featureSrvc.Dispose();
            resourceSrvc.Dispose();

            if (nSloj > 0)
            {
                litPrebodi.Text = sbOut.ToString();
            }
            else
            {
                litPrebodiTitle.Visible = false;
                litPrebodi.Text         = "<b>" + "None layer lies below the selected item/area!" + "</b>";
            }

            MgGeometry inGeom = wktrw.Read(GEOMETRY);

            double rw = map.ViewScale / Math.Sqrt(inGeom.Area);

            //koordinate
            if (hasInputGeom & rw > 400)
            {
                string output = "";

                output = pointTransformAndWriteZ(GEOMETRY, map);

                litKoordinate.Text      = output;
                litKoordinateTitle.Text = "Coordinates of selected points:";
            }
        }
    }
Esempio n. 9
0
        public static void EmitLocationResults(MgFeatureService featureService, MgResourceIdentifier locationMarkerDataResId, String mgSessionId, HttpResponse response)
        {
            //targets.InnerHtml+="<table class=\"RegText\" border=\"0\" cellspacing=\"0\" width=\"100%\">";
            //targets.InnerHtml+="<tr><td class=\"SubTitle\">תוצאות</td></tr>";

            MgAgfReaderWriter geometryReaderWriter = new MgAgfReaderWriter();
            MgFeatureReader featureReader = featureService.SelectFeatures(locationMarkerDataResId, "LocationMarker", null);

            while (featureReader.ReadNext())
            {
                String address = featureReader.GetString("Address");
                MgByteReader byteReader = featureReader.GetGeometry("Location");

                MgPoint point = geometryReaderWriter.Read(byteReader) as MgPoint;
                double x = point.GetCoordinate().GetX();
                double y = point.GetCoordinate().GetY();

                //    targets.InnerHtml+="<tr><td>";
                //   targets.InnerHtml+="<img src=\"../images/pushpinblue.jpg\">";
                //    targets.InnerHtml += "<a href=\"gotopoint.aspx?X=" + x + "&Y=" + y + "&Scale=10000\" target=\"scriptFrame\">X: " + x + ", Y: " + y + "</a></td></tr>";
            }
            featureReader.Close();

            //targets.InnerHtml+="</table>";
            // targets.InnerHtml+="<form action=\"clearlocationresults.aspx\" method=\"get\" target=\"scriptFrame\">";
            //targets.InnerHtml+="<input type=\"hidden\" name=\"SESSION\" value=\"" + mgSessionId + "\">";
            // targets.InnerHtml+="<input type=\"button\" class=\"Ctrl\" value=\"נקה תוצאות \" onClick=\"javascript:submit()\">";
            //targets.InnerHtml+="</form>";
            // targets.InnerHtml+="<hr>";
        }