private IEnvelope ClassEnvelope(IClass Class, ISpatialReference sRef)
        {
            IEnvelope         envelope  = null;
            ISpatialReference classSRef = null;

            if (Class is IFeatureClass)
            {
                envelope  = ((IFeatureClass)Class).Envelope;
                classSRef = ((IFeatureClass)Class).SpatialReference;
            }
            else if (Class is IRasterClass && ((IRasterClass)Class).Polygon != null)
            {
                envelope  = ((IRasterClass)Class).Polygon.Envelope;
                classSRef = ((IRasterClass)Class).SpatialReference;
            }

            if (envelope != null && classSRef != null && sRef != null && !sRef.Equals(classSRef))
            {
                IGeometry geom = GeometricTransformer.Transform2D(envelope, classSRef, sRef);
                if (geom == null)
                {
                    return(null);
                }

                envelope = geom.Envelope;
            }
            return(envelope);
        }
Example #2
0
            void zoom2max_Click(object sender, EventArgs e)
            {
                if (_doc == null || _doc.FocusMap == null || _doc.FocusMap.Display == null ||
                    _ovmap == null || _ovmap.Display == null)
                {
                    return;
                }

                IEnvelope extent = _doc.FocusMap.Display.Limit;

                if (_doc.FocusMap.Display.SpatialReference != null &&
                    !_doc.FocusMap.Display.SpatialReference.Equals(_ovmap.Display.SpatialReference))
                {
                    extent = GeometricTransformer.Transform2D(
                        extent,
                        _doc.FocusMap.Display.SpatialReference,
                        _ovmap.Display.SpatialReference).Envelope;
                }

                _ovmap.Display.ZoomTo(extent);

                if (RefreshOverviewMap != null)
                {
                    RefreshOverviewMap();
                }
            }
Example #3
0
 public IPoint GetPoint(ISpatialReference sRef)
 {
     return(GeometricTransformer.Transform2D(
                coordControl1.Point,
                coordControl1.SpatialReference,
                sRef) as IPoint);
 }
Example #4
0
        public void OnEvent(object MapEvent)
        {
            if (_mapDocument == null || Device.GPS == null || _mapDocument.Application == null)
            {
                return;
            }

            IMap map = _mapDocument.FocusMap;

            if (map == null || map.Display == null)
            {
                return;
            }
            GPSDevice gps = Device.GPS;

            if (gps == null)
            {
                return;
            }

            if (_gpspoint != null)  // Punkt aus der Karte entfernen
            {
                gps.PositionReceived -= new GPSDevice.PositionReceivedEventHandler(gps_PositionReceived);
                map.Display.GraphicsContainer.Elements.Remove(_gpspoint);
                _gpspoint = null;

                if (_mapDocument.Application is IMapApplication)
                {
                    ((IMapApplication)_mapDocument.Application).RefreshActiveMap(DrawPhase.Graphics);
                }
                return;
            }

            if (map.Display == null || map.Display.SpatialReference == null)
            {
                MessageBox.Show("No Spatialreference definded for current map...");
                return;
            }

            IPoint point = GeometricTransformer.Transform2D(new Point(gps.Longitude, gps.Latitude),
                                                            SpatialReference.FromID("EPSG:4326"), map.Display.SpatialReference) as IPoint;

            if (point != null)
            {
                double width  = map.Display.Envelope.maxx - map.Display.Envelope.minx;
                double height = map.Display.Envelope.maxy - map.Display.Envelope.miny;

                map.Display.ZoomTo(new Envelope(point.X - width / 2, point.Y - height / 2, point.X + width / 2, point.Y + height / 2));
                map.Display.GraphicsContainer.Elements.Add(_gpspoint = new GPSPoint(gps.Longitude, gps.Latitude, true));

                if (_mapDocument.Application is IMapApplication)
                {
                    ((IMapApplication)_mapDocument.Application).RefreshActiveMap(DrawPhase.All);
                }

                _timeStamp            = DateTime.Now;
                gps.PositionReceived += new GPSDevice.PositionReceivedEventHandler(gps_PositionReceived);
            }
        }
Example #5
0
        public void OnEvent(object element, object dataset)
        {
            if (_doc == null || _doc.FocusMap == null || _doc.FocusMap.Display == null)
            {
                return;
            }

            if (element is IFeatureLayer && ((IFeatureLayer)element).FeatureClass != null && ((IFeatureLayer)element).FeatureClass.Envelope != null)
            {
                IEnvelope envelope = ((IFeatureLayer)element).FeatureClass.Envelope;
                if (((IFeatureLayer)element).FeatureClass.SpatialReference != null && !((IFeatureLayer)element).FeatureClass.SpatialReference.Equals(_doc.FocusMap.Display.SpatialReference))
                {
                    IGeometry geom = GeometricTransformer.Transform2D(envelope, ((IFeatureLayer)element).FeatureClass.SpatialReference, _doc.FocusMap.Display.SpatialReference);
                    if (geom == null)
                    {
                        return;
                    }
                    envelope = geom.Envelope;
                }
                _doc.FocusMap.Display.ZoomTo(envelope);
            }
            else if (element is IRasterLayer && ((IRasterLayer)element).RasterClass != null && ((IRasterLayer)element).RasterClass.Polygon != null)
            {
                IEnvelope envelope = ((IRasterLayer)element).RasterClass.Polygon.Envelope;
                if (((IRasterLayer)element).RasterClass.SpatialReference != null && !((IRasterLayer)element).RasterClass.SpatialReference.Equals(_doc.FocusMap.Display.SpatialReference))
                {
                    IGeometry geom = GeometricTransformer.Transform2D(envelope, ((IRasterLayer)element).RasterClass.SpatialReference, _doc.FocusMap.Display.SpatialReference);
                    if (geom == null)
                    {
                        return;
                    }
                    envelope = geom.Envelope;
                }
                _doc.FocusMap.Display.ZoomTo(envelope);
            }
            else if (element is IWebServiceLayer && ((IWebServiceLayer)element).WebServiceClass != null && ((IWebServiceLayer)element).WebServiceClass.Envelope != null)
            {
                IEnvelope envelope = ((IWebServiceLayer)element).WebServiceClass.Envelope;
                if (((IWebServiceLayer)element).WebServiceClass.SpatialReference != null && !((IWebServiceLayer)element).WebServiceClass.SpatialReference.Equals(_doc.FocusMap.Display.SpatialReference))
                {
                    IGeometry geom = GeometricTransformer.Transform2D(envelope, ((IWebServiceLayer)element).WebServiceClass.SpatialReference, _doc.FocusMap.Display.SpatialReference);
                    if (geom == null)
                    {
                        return;
                    }
                    envelope = geom.Envelope;
                }
                _doc.FocusMap.Display.ZoomTo(envelope);
            }
            else
            {
                return;
            }
            if (_doc.Application is IMapApplication)
            {
                ((IMapApplication)_doc.Application).RefreshActiveMap(DrawPhase.All);
            }
        }
Example #6
0
            public void OnEvent(object MapEvent)
            {
                if (_doc == null || _doc.FocusMap == null || _doc.FocusMap.Display == null)
                {
                    return;
                }
                if (!(MapEvent is MapEventRubberband))
                {
                    return;
                }

                MapEventRubberband ev = (MapEventRubberband)MapEvent;

                if (ev.Map == null)
                {
                    return;
                }

                if (!(ev.Map.Display is Display))
                {
                    return;
                }
                Display nav = (Display)ev.Map.Display;

                IEnvelope extent = new Envelope(ev.minX, ev.minY, ev.maxX, ev.maxY);

                if (ev.Map.Display.SpatialReference != null &&
                    !ev.Map.Display.SpatialReference.Equals(_doc.FocusMap.Display.SpatialReference))
                {
                    extent = GeometricTransformer.Transform2D(
                        extent,
                        ev.Map.Display.SpatialReference,
                        _doc.FocusMap.Display.SpatialReference).Envelope;
                }
                if (Math.Abs(ev.maxX - ev.minX) < 1e-5 ||
                    Math.Abs(ev.maxY - ev.minY) < 1e-5)
                {
                    IEnvelope dispEnv = new Envelope(_doc.FocusMap.Display.Envelope);
                    dispEnv.Center = extent.Center;
                    _doc.FocusMap.Display.ZoomTo(dispEnv);
                }
                else
                {
                    _doc.FocusMap.Display.ZoomTo(extent);
                }

                if (_doc.Application is IMapApplication)
                {
                    ((IMapApplication)_doc.Application).RefreshActiveMap(DrawPhase.All);
                }

                //ev.refreshMap = true;
                //ev.drawPhase = DrawPhase.Graphics;
            }
Example #7
0
 internal IPoint Project(IDisplay display)
 {
     if (display.SpatialReference != null)
     {
         return(GeometricTransformer.Transform2D(new Point(_lon, _lat),
                                                 SpatialReference.FromID("EPSG:4326"), display.SpatialReference) as IPoint);
     }
     else
     {
         return(new Point(_lon, _lat));
     }
 }
Example #8
0
 private IPolyline Project(IDisplay display)
 {
     if (display.SpatialReference != null)
     {
         return(GeometricTransformer.Transform2D(_polyline,
                                                 SpatialReference.FromID("EPSG:4326"), display.SpatialReference) as IPolyline);
     }
     else
     {
         return(_polyline);
     }
 }
Example #9
0
        static private string GetBBox(IEnvelope env, GeometricTransformer transformer)
        {
            try
            {
                env = ((IGeometry)transformer.Transform2D(env)).Envelope;

                return(Math.Round(env.minx, 7).ToString(_nhi) + "," +
                       Math.Round(env.miny, 7).ToString(_nhi) + "," +
                       Math.Round(env.maxx, 7).ToString(_nhi) + "," +
                       Math.Round(env.maxy, 7).ToString(_nhi));
            }
            catch { return(String.Empty); }
        }
Example #10
0
        public float GridQuery(gView.Framework.Carto.IDisplay display, IPoint point, ISpatialReference sRef)
        {
            TFWFile tfw = this.WorldFile as TFWFile;

            if (tfw == null)
            {
                return((float)_nodata);
            }

            if (this.SpatialReference != null && sRef != null &&
                !sRef.Equals(this.SpatialReference))
            {
                point = GeometricTransformer.Transform2D(point, sRef, this.SpatialReference) as IPoint;
            }
            if (point == null)
            {
                return((float)_nodata);
            }

            // Punkt transformieren -> Bild
            vector2[] vecs = new vector2[1];
            vecs[0] = new vector2(point.X, point.Y);

            if (!tfw.ProjectInv(vecs))
            {
                return((float)_nodata);
            }
            if (vecs[0].x < 0 || vecs[0].x >= _iWidth ||
                vecs[0].y < 0 || vecs[0].y >= _iHeight)
            {
                return((float)_nodata);
            }

            unsafe
            {
                fixed(float *buf = new float[2])
                {
                    _gridQueryBand.ReadRaster((int)vecs[0].x, (int)vecs[0].y, 1, 1,
                                              (IntPtr)buf,
                                              1, 1, OSGeo.GDAL.DataType.GDT_CFloat32, 4, 0);

                    if ((_hasNoDataVal != 0 && buf[0] == _nodata) ||
                        (_useIgnoreValue && buf[0] == _ignoreValue))
                    {
                        return((float)_nodata);
                    }

                    return(buf[0]);
                }
            }
        }
Example #11
0
        public bool PerformUpdateFeature(IFeatureClass fc, IFeature feature)
        {
            if (fc == null || feature == null ||
                fc.Dataset == null ||
                !(fc.Dataset.Database is IFeatureUpdater))
            {
                return(false);
            }

            if (_attributEditor != null && !_attributEditor.CommitValues())
            {
                MessageBox.Show(_attributEditor.lastErrorMsg, "ERROR: Commit Values...");
                return(false);
            }

            EditorEventArgument args = new EditorEventArgument(fc, feature);

            if (OnUpdateFeature != null)
            {
                OnUpdateFeature(this, args);
            }
            if (args.Cancel)
            {
                _lastMsg = args.Message;
                return(false);
            }

            IGeometry shape = feature.Shape;

            if (_doc != null &&
                _doc.FocusMap != null &&
                _doc.FocusMap.Display != null &&
                _doc.FocusMap.Display.SpatialReference != null &&
                !_doc.FocusMap.Display.SpatialReference.Equals(_fc.SpatialReference))
            {
                feature.Shape = GeometricTransformer.Transform2D(
                    feature.Shape,
                    _doc.FocusMap.Display.SpatialReference,
                    _fc.SpatialReference);
            }
            bool ret = ((IFeatureUpdater)fc.Dataset.Database).Update(fc, feature);

            feature.Shape = shape;

            if (!ret)
            {
                _lastMsg = fc.Dataset.Database.lastErrorMsg;
            }
            return(ret);
        }
Example #12
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (_map == null || _display == null)
            {
                return;
            }

            try
            {
                _map.Name         = txtName.Text;
                _display.refScale = Convert.ToDouble(numRefScale.Value);

                if (cmbMapUnits.Enabled)
                {
                    _display.MapUnits = ((GeoUnitsItem)cmbMapUnits.SelectedItem).Unit;
                }
                _display.DisplayUnits = ((GeoUnitsItem)cmbDisplayUnits.SelectedItem).Unit;

                _display.BackgroundColor = btnBackgroundColor.BackColor;

                ISpatialReference oldSRef = _display.SpatialReference;
                _display.SpatialReference = _sr.SpatialReference;

                if (oldSRef != null &&
                    !oldSRef.Equals(_display.SpatialReference))
                {
                    IEnvelope limit = _display.Limit;
                    IEnvelope env   = _display.Envelope;

                    _display.Limit = GeometricTransformer.Transform2D(
                        limit,
                        oldSRef,
                        _display.SpatialReference).Envelope;

                    _display.ZoomTo(
                        GeometricTransformer.Transform2D(
                            env,
                            oldSRef,
                            _display.SpatialReference).Envelope
                        );
                }

                _map.LayerDefaultSpatialReference = _sr2.SpatialReference;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #13
0
        private IEnvelope ProjectEnvelope(IEnvelope env, ISpatialReference sRef)
        {
            if (sRef == null || env == null || _sRef == null)
            {
                return(env);
            }

            IGeometry geom = GeometricTransformer.Transform2D(env, sRef, _sRef);

            if (geom != null)
            {
                return(geom.Envelope);
            }

            return(null);
        }
Example #14
0
        public ICursor PointQuery(gView.Framework.Carto.IDisplay display, IPoint point, ISpatialReference sRef, IUserData userdata)
        {
            TFWFile tfw = this.WorldFile as TFWFile;

            if (tfw == null)
            {
                return(null);
            }

            if (this.SpatialReference != null && sRef != null &&
                !sRef.Equals(this.SpatialReference))
            {
                point = GeometricTransformer.Transform2D(point, sRef, this.SpatialReference) as IPoint;
            }
            if (point == null)
            {
                return(null);
            }

            // Punkt transformieren -> Bild
            vector2[] vecs = new vector2[1];
            vecs[0] = new vector2(point.X, point.Y);

            if (!tfw.ProjectInv(vecs))
            {
                return(null);
            }
            if (vecs[0].x < 0 || vecs[0].x >= _iWidth ||
                vecs[0].y < 0 || vecs[0].y >= _iHeight)
            {
                return(null);
            }

            switch (_type)
            {
            case RasterType.image:
                return(QueryImage((int)Math.Floor(vecs[0].x), (int)Math.Floor(vecs[0].y)));

            case RasterType.grid:
                return(QueryGrid((int)Math.Floor(vecs[0].x), (int)Math.Floor(vecs[0].y)));
            }

            return(null);
        }
Example #15
0
        public bool ProjectTo(ISpatialReference sRef)
        {
            if (_bounds == null)
            {
                return(false);
            }

            if (_sRef != null && !_sRef.Equals(sRef))
            {
                IGeometry result = GeometricTransformer.Transform2D(_bounds, _sRef, sRef);
                if (result != null && result.Envelope != null)
                {
                    _bounds = result.Envelope;
                    _sRef   = sRef;
                    return(true);
                }
            }
            return(true);
        }
Example #16
0
            public IEnvelope Envelope(string srs)
            {
                IEnvelope env = null;

                _boundaryBoxes.TryGetValue(srs.ToUpper(), out env);

                if (env == null && LatLonBoundingBox != null)
                {
                    // Projezieren
                    ISpatialReference sRef      = gView.Framework.Geometry.SpatialReference.FromID(srs);
                    ISpatialReference epsg_4326 = gView.Framework.Geometry.SpatialReference.FromID("epsg:4326");

                    IGeometry geom = GeometricTransformer.Transform2D(LatLonBoundingBox, epsg_4326, sRef);
                    if (geom != null)
                    {
                        env = geom.Envelope;
                    }
                }

                return((env != null) ? env : new Envelope(-180, -90, 180, 90));
            }
Example #17
0
        private void InsertMapExtent(IDisplay display)
        {
            if (_ovmap == null || display == null ||
                _ovmap.Display == null)
            {
                return;
            }

            IGeometry mapEnv = display.Envelope;

            _ovmap.Display.GraphicsContainer.Elements.Clear();
            if (display.SpatialReference != null &&
                !display.SpatialReference.Equals(_ovmap.Display.SpatialReference))
            {
                mapEnv = GeometricTransformer.Transform2D(
                    mapEnv, display.SpatialReference,
                    _ovmap.Display.SpatialReference);
            }

            _envGraphics.LimitEnvelope = _ovmap.Display.Envelope;
            _envGraphics.Geometry      = mapEnv;
            _ovmap.Display.GraphicsContainer.Elements.Add(_envGraphics);
        }
Example #18
0
        private void WmtsCapabilities100(IServiceRequestContext context, TileServiceMetadata metadata)
        {
            gView.Framework.OGC.WMTS.Version_1_0_0.Capabilities capabilities = new Framework.OGC.WMTS.Version_1_0_0.Capabilities()
            {
                version = "1.0.0"
            };

            capabilities.NameSpaces = new System.Xml.Serialization.XmlSerializerNamespaces();
            capabilities.NameSpaces.Add("ows", "http://www.opengis.net/ows/1.1");
            capabilities.NameSpaces.Add("xlink", "http://www.w3.org/1999/xlink");
            capabilities.NameSpaces.Add("gml", "http://www.opengis.net/gml");

            #region ServiceIndentification

            capabilities.ServiceIdentification       = new gView.Framework.OGC.WMTS.Version_1_0_0.ServiceIdentification();
            capabilities.ServiceIdentification.Title = new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType()
                                                                                                                         {
                                                                                                                             Value = context.ServiceMap.Name
                                                                                                                         } };
            capabilities.ServiceIdentification.ServiceType = new gView.Framework.OGC.WMTS.Version_1_0_0.CodeType()
            {
                Value = "OGC WMTS"
            };
            capabilities.ServiceIdentification.ServiceTypeVersion = new string[] { "1.0.0" };

            #endregion

            string restFulUrl = context.ServiceRequest.OnlineResource.ToLower().Replace("/maprequest/wmts/", "/tilewmts/");

            #region OperationsMetadata

            capabilities.OperationsMetadata = new gView.Framework.OGC.WMTS.Version_1_0_0.OperationsMetadata();

            var getCapOperation = new gView.Framework.OGC.WMTS.Version_1_0_0.Operation()
            {
                name = "GetCapabilities"
            };
            getCapOperation.DCP               = new gView.Framework.OGC.WMTS.Version_1_0_0.DCP[] { new gView.Framework.OGC.WMTS.Version_1_0_0.DCP() };
            getCapOperation.DCP[0].Item       = new gView.Framework.OGC.WMTS.Version_1_0_0.HTTP();
            getCapOperation.DCP[0].Item.Items = new gView.Framework.OGC.WMTS.Version_1_0_0.RequestMethodType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.RequestMethodType() };

            getCapOperation.DCP[0].Item.Items[0].href                        = context.ServiceRequest.OnlineResource + "?SERVICE=WMTS&VERSION=1.0.0" + "&";
            getCapOperation.DCP[0].Item.Items[0].Constraint                  = new gView.Framework.OGC.WMTS.Version_1_0_0.DomainType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.DomainType() };
            getCapOperation.DCP[0].Item.Items[0].Constraint[0].name          = "GetEncoding";
            getCapOperation.DCP[0].Item.Items[0].Constraint[0].AllowedValues = new object[] { new gView.Framework.OGC.WMTS.Version_1_0_0.ValueType()
                                                                                              {
                                                                                                  Value = "KVP"                                                      /*"RESTful"*/
                                                                                              } };
            getCapOperation.DCP[0].Item.ItemsElementName = new gView.Framework.OGC.WMTS.Version_1_0_0.ItemsChoiceType[] { gView.Framework.OGC.WMTS.Version_1_0_0.ItemsChoiceType.Get };


            var getTileOperation = new gView.Framework.OGC.WMTS.Version_1_0_0.Operation()
            {
                name = "GetTile"
            };
            getTileOperation.DCP               = new gView.Framework.OGC.WMTS.Version_1_0_0.DCP[] { new gView.Framework.OGC.WMTS.Version_1_0_0.DCP() };
            getTileOperation.DCP[0].Item       = new gView.Framework.OGC.WMTS.Version_1_0_0.HTTP();
            getTileOperation.DCP[0].Item.Items = new gView.Framework.OGC.WMTS.Version_1_0_0.RequestMethodType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.RequestMethodType() };

            getTileOperation.DCP[0].Item.Items[0].href                        = restFulUrl;
            getTileOperation.DCP[0].Item.Items[0].Constraint                  = new gView.Framework.OGC.WMTS.Version_1_0_0.DomainType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.DomainType() };
            getTileOperation.DCP[0].Item.Items[0].Constraint[0].name          = "GetEncoding";
            getTileOperation.DCP[0].Item.Items[0].Constraint[0].AllowedValues = new object[] { new gView.Framework.OGC.WMTS.Version_1_0_0.ValueType()
                                                                                               {
                                                                                                   Value = "RESTful"
                                                                                               } };
            getTileOperation.DCP[0].Item.ItemsElementName = new gView.Framework.OGC.WMTS.Version_1_0_0.ItemsChoiceType[] { gView.Framework.OGC.WMTS.Version_1_0_0.ItemsChoiceType.Get };

            capabilities.OperationsMetadata.Operation = new gView.Framework.OGC.WMTS.Version_1_0_0.Operation[]
            {
                getCapOperation, getTileOperation
            };

            #endregion

            #region Contents

            capabilities.Contents = new gView.Framework.OGC.WMTS.Version_1_0_0.ContentsType();

            List <gView.Framework.OGC.WMTS.Version_1_0_0.LayerType>     layers     = new List <gView.Framework.OGC.WMTS.Version_1_0_0.LayerType>();
            List <gView.Framework.OGC.WMTS.Version_1_0_0.TileMatrixSet> matrixSets = new List <gView.Framework.OGC.WMTS.Version_1_0_0.TileMatrixSet>();

            ISpatialReference sRef4326 = SpatialReference.FromID("epsg:4326");

            foreach (var epsg in metadata.EPSGCodes)
            {
                IEnvelope extent = metadata.GetEPSGEnvelope(epsg);
                if (extent == null)
                {
                    continue;
                }
                IPoint origin = metadata.GetOriginUpperLeft(epsg);
                if (origin == null)
                {
                    continue;
                }

                ISpatialReference sRef       = SpatialReference.FromID("epsg:" + epsg);
                IEnvelope         extent4326 = GeometricTransformer.Transform2D(extent, sRef, sRef4326).Envelope;

                if (double.IsInfinity(extent4326.minx))
                {
                    extent4326.minx = -180D;
                }
                if (double.IsInfinity(extent4326.miny))
                {
                    extent4326.miny = -90D;
                }
                if (double.IsInfinity(extent4326.maxx))
                {
                    extent4326.maxx = 180D;
                }
                if (double.IsInfinity(extent4326.maxy))
                {
                    extent4326.maxy = 90D;
                }

                foreach (string cacheType in new string[] { "classic", "compact" })
                {
                    string epsgPath = _mapServer.TileCachePath + @"\" + context.ServiceMap.Name + @"\_alllayers\" + (cacheType == "compact" ? @"compact\" : "") +
                                      TileServiceMetadata.EpsgPath(GridOrientation.UpperLeft, epsg);

                    if (!new DirectoryInfo(epsgPath).Exists)
                    {
                        continue;
                    }

                    #region Layer

                    string layerName = context.ServiceMap.Name + " EPSG:" + epsg + " " + cacheType;
                    string layerId   = context.ServiceMap.Name.ToLower().Replace(" ", "_") + "_" + epsg + "_" + cacheType;

                    var layer = new gView.Framework.OGC.WMTS.Version_1_0_0.LayerType();

                    layer.Title = new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType()
                                                                                                    {
                                                                                                        Value = layerName
                                                                                                    } };
                    layer.Identifier = new gView.Framework.OGC.WMTS.Version_1_0_0.CodeType()
                    {
                        Value = layerId
                    };

                    List <gView.Framework.OGC.WMTS.Version_1_0_0.Style> styles = new List <Framework.OGC.WMTS.Version_1_0_0.Style>();
                    //styles.Add(new gView.Framework.OGC.WMTS.Version_1_0_0.Style()
                    //{
                    //    Title = new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType() { Value = "Default Style" } },
                    //    Identifier = new gView.Framework.OGC.WMTS.Version_1_0_0.CodeType() { Value = "default" }
                    //});
                    foreach (var styleVal in Enum.GetValues(typeof(ImageProcessingFilters)))
                    {
                        string name = Enum.GetName(typeof(ImageProcessingFilters), styleVal);
                        styles.Add(new Framework.OGC.WMTS.Version_1_0_0.Style()
                        {
                            Title = new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType()
                                                                                                      {
                                                                                                          Value = name
                                                                                                      } },
                            Identifier = new gView.Framework.OGC.WMTS.Version_1_0_0.CodeType()
                            {
                                Value = name.ToLower()
                            }
                        });
                    }

                    layer.Style = styles.ToArray();

                    #region BoundingBox

                    layer.BoundingBox = new gView.Framework.OGC.WMTS.Version_1_0_0.BoundingBoxType[]
                    {
                        new gView.Framework.OGC.WMTS.Version_1_0_0.BoundingBoxType()
                        {
                            crs         = "urn:ogc:def:crs:EPSG::" + epsg,
                            LowerCorner = PointToString(extent.LowerLeft, sRef),
                            UpperCorner = PointToString(extent.UpperRight, sRef)
                        }
                    };
                    layer.WGS84BoundingBox = new gView.Framework.OGC.WMTS.Version_1_0_0.WGS84BoundingBoxType[]
                    {
                        new gView.Framework.OGC.WMTS.Version_1_0_0.WGS84BoundingBoxType()
                        {
                            crs         = "urn:ogc:def:crs:OGC:2:84", // urn:ogc:def:crs:OGC:2:84
                            LowerCorner = PointToString(extent4326.LowerLeft, sRef4326),
                            UpperCorner = PointToString(extent4326.UpperRight, sRef4326)
                        }
                    };

                    #endregion

                    layer.TileMatrixSetLink = new gView.Framework.OGC.WMTS.Version_1_0_0.TileMatrixSetLink[]
                    {
                        new gView.Framework.OGC.WMTS.Version_1_0_0.TileMatrixSetLink()
                        {
                            TileMatrixSet = layerId + "_default_matrixset"
                        }
                    };

                    List <string> formats = new List <string>();
                    if (metadata.FormatJpg)
                    {
                        formats.Add("image/jpg");
                    }
                    if (metadata.FormatPng)
                    {
                        formats.Add("image/png");
                    }
                    layer.Format = formats.ToArray();

                    List <Framework.OGC.WMTS.Version_1_0_0.URLTemplateType> resourceURLs = new List <Framework.OGC.WMTS.Version_1_0_0.URLTemplateType>();
                    if (metadata.FormatJpg)
                    {
                        resourceURLs.Add(new Framework.OGC.WMTS.Version_1_0_0.URLTemplateType()
                        {
                            resourceType = Framework.OGC.WMTS.Version_1_0_0.URLTemplateTypeResourceType.tile,
                            format       = "image/jpg",
                            template     = restFulUrl + "/" + cacheType + "/ul/" + epsg + "/{Style}/{TileMatrix}/{TileRow}/{TileCol}.jpg"
                        });
                    }
                    if (metadata.FormatPng)
                    {
                        resourceURLs.Add(new Framework.OGC.WMTS.Version_1_0_0.URLTemplateType()
                        {
                            resourceType = Framework.OGC.WMTS.Version_1_0_0.URLTemplateTypeResourceType.tile,
                            format       = "image/png",
                            template     = restFulUrl + "/" + cacheType + "/ul/" + epsg + "/{Style}/{TileMatrix}/{TileRow}/{TileCol}.png"
                        });
                    }
                    layer.ResourceURL = resourceURLs.ToArray();

                    layers.Add(layer);

                    #endregion

                    #region Matrix Set

                    double matrixSetWidth  = extent.Width;
                    double matrixSetHeight = extent.Height;

                    var matrixSet = new gView.Framework.OGC.WMTS.Version_1_0_0.TileMatrixSet();

                    matrixSet.Title = new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType[] { new gView.Framework.OGC.WMTS.Version_1_0_0.LanguageStringType()
                                                                                                        {
                                                                                                            Value = layerName + " Default Matrix Set"
                                                                                                        } };
                    matrixSet.Identifier = new gView.Framework.OGC.WMTS.Version_1_0_0.CodeType()
                    {
                        Value = layerId + "_default_matrixset"
                    };
                    matrixSet.SupportedCRS = "urn:ogc:def:crs:EPSG::" + epsg;

                    matrixSet.TileMatrix = new gView.Framework.OGC.WMTS.Version_1_0_0.TileMatrix[metadata.Scales.Count];

                    #region DPI

                    double inchMeter = 0.0254;                    /* 0.0254000508001016;*/
                    double dpi       = inchMeter * 1000D / 0.28D; // wmts 0.28mm -> 1 Pixel;
                    double dpm       = dpi / inchMeter;

                    #endregion

                    for (int s = 0, to = metadata.Scales.Count; s < to; s++)
                    {
                        string scalePath = _mapServer.TileCachePath + @"\" + context.ServiceMap.Name + @"\_alllayers\" + (cacheType == "compact" ? @"compact\" : "") +
                                           TileServiceMetadata.ScalePath(GridOrientation.UpperLeft, epsg, metadata.Scales[s]);

                        if (!new DirectoryInfo(scalePath).Exists)
                        {
                            break;
                        }

                        double resolution = metadata.Scales[s] / (metadata.Dpi / inchMeter);

                        matrixSet.TileMatrix[s]            = new gView.Framework.OGC.WMTS.Version_1_0_0.TileMatrix();
                        matrixSet.TileMatrix[s].Identifier = new gView.Framework.OGC.WMTS.Version_1_0_0.CodeType()
                        {
                            Value = s.ToString()
                        };
                        matrixSet.TileMatrix[s].TopLeftCorner = PointToString(origin, sRef);
                        matrixSet.TileMatrix[s].TileWidth     = metadata.TileWidth.ToString();
                        matrixSet.TileMatrix[s].TileHeight    = metadata.TileHeight.ToString();

                        double tileWidth  = metadata.TileWidth * resolution;
                        double tileHeight = metadata.TileHeight * resolution;

                        int matrixWidth  = (int)Math.Round(matrixSetWidth / tileWidth + 0.5);
                        int matrixHeight = (int)Math.Round(matrixSetHeight / tileHeight + 0.5);

                        matrixSet.TileMatrix[s].MatrixWidth      = matrixWidth.ToString();
                        matrixSet.TileMatrix[s].MatrixHeight     = matrixHeight.ToString();
                        matrixSet.TileMatrix[s].ScaleDenominator = resolution * dpm;
                    }

                    matrixSets.Add(matrixSet);

                    #endregion
                }
            }

            capabilities.Contents.DatasetDescriptionSummary = layers.ToArray();
            capabilities.Contents.TileMatrixSet             = matrixSets.ToArray();

            #endregion

            XsdSchemaSerializer <gView.Framework.OGC.WMTS.Version_1_0_0.Capabilities> ser = new XsdSchemaSerializer <gView.Framework.OGC.WMTS.Version_1_0_0.Capabilities>();
            string xml = ser.Serialize(capabilities, null);

            xml = xml.Replace(@"<ows:DatasetDescriptionSummary xsi:type=""LayerType"">", "<Layer>");
            xml = xml.Replace(@"</ows:DatasetDescriptionSummary>", "</Layer>");

            context.ServiceRequest.Response = xml;
        }
Example #19
0
        public void AddFeature(IFeature feature, ISpatialReference sRef, IFeatureLayer layer, string Category, IFields fields, IField primaryDisplayField)
        {
            if (feature == null)
            {
                return;
            }

            if (layer != null)
            {
                if (fields == null)
                {
                    fields = layer.Fields;
                }
                if (primaryDisplayField == null)
                {
                    primaryDisplayField = layer.Fields.PrimaryDisplayField;
                }
            }

            if (Category == "")
            {
                Category = "Results";
            }
            CategoryTreeNode parent = null;

            foreach (CategoryTreeNode node in treeObjects.Nodes)
            {
                if (node.Category == Category)
                {
                    parent = node;
                    break;
                }
            }
            if (parent == null)
            {
                parent = new CategoryTreeNode(Category);
                treeObjects.Nodes.Add(parent);
            }

            parent.Nodes.Add(new FeatureTreeNode(_doc, feature, sRef, layer, (primaryDisplayField != null) ? primaryDisplayField.name : "", 1));

            if (fields != null && feature.Fields != null)
            {
                List <FieldValue> fvs = gView.Framework.system.ListOperations <FieldValue> .Clone(feature.Fields);

                feature.Fields.Clear();

                foreach (IField field in fields.ToEnumerable())
                {
                    if (!field.visible)
                    {
                        continue;
                    }
                    for (int i = 0; i < fvs.Count; i++)
                    {
                        if (fvs[i].Name == field.name)
                        {
                            feature.Fields.Add(new FieldValue(field.aliasname, fvs[i].Value));
                            fvs.RemoveAt(i);
                            break;
                        }
                    }
                }
            }

            if (treeObjects.SelectedNode == null)
            {
                treeObjects.SelectedNode = parent.Nodes[0];

                if (_doc != null && _doc.FocusMap != null && _doc.FocusMap.Display != null)
                {
                    IGeometry shape = feature.Shape;
                    if (sRef != null && !sRef.Equals(_doc.FocusMap.Display.SpatialReference))
                    {
                        shape = GeometricTransformer.Transform2D(shape, sRef, _doc.FocusMap.Display.SpatialReference);
                    }
                    _doc.FocusMap.HighlightGeometry(shape, 300);
                }
                //parent.ExpandAll();
                parent.Expand();
                if (parent.Nodes.Count > 0)
                {
                    parent.Nodes[0].Expand();
                }
            }
        }
Example #20
0
        private void treeObjects_MouseClick(object sender, MouseEventArgs e)
        {
            if (_doc == null)
            {
                return;
            }
            if (_doc.FocusMap == null)
            {
                return;
            }
            if (_doc.FocusMap.Display == null)
            {
                return;
            }
            if (_doc.Application == null)
            {
                return;
            }

            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            TreeNode node = treeObjects.GetNodeAt(e.X, e.Y);

            if (/*node == treeObjects.SelectedNode &&*/ node is FeatureTreeNode)
            {
                IFeature          feature = ((FeatureTreeNode)node).Feature;
                ISpatialReference sRef    = ((FeatureTreeNode)node).SpatialReference;
                ILayer            layer   = ((FeatureTreeNode)node).Layer;

                if (feature != null && feature.Shape != null)
                {
                    if (e.X > 50)
                    {
                        IGeometry shape = feature.Shape;
                        if (sRef != null && !sRef.Equals(_doc.FocusMap.Display.SpatialReference))
                        {
                            shape = GeometricTransformer.Transform2D(shape, sRef, _doc.FocusMap.Display.SpatialReference);
                        }
                        _doc.FocusMap.HighlightGeometry(shape, 300);
                    }
                    else if (e.X >= 38)
                    {
                        IEnvelope envelope = feature.Shape.Envelope;
                        if (sRef != null && !sRef.Equals(_doc.FocusMap.Display.SpatialReference))
                        {
                            IGeometry geom = GeometricTransformer.Transform2D(envelope,
                                                                              sRef,
                                                                              _doc.FocusMap.Display.SpatialReference);
                            if (geom == null)
                            {
                                return;
                            }
                            envelope = geom.Envelope;
                        }
                        _doc.FocusMap.Display.ZoomTo(envelope);
                        if (layer != null && layer.MaximumZoomToFeatureScale > _doc.FocusMap.Display.mapScale)
                        {
                            _doc.FocusMap.Display.mapScale = layer.MaximumZoomToFeatureScale;
                        }
                        if (_doc.Application is IMapApplication)
                        {
                            ((IMapApplication)_doc.Application).RefreshActiveMap(DrawPhase.All);
                        }
                    }
                }
            }
        }
Example #21
0
        private void cmbEpsg_SelectedIndexChanged(object sender, EventArgs e)
        {
            lstScales.Items.Clear();

            if (_metadata == null)
            {
                return;
            }

            ISpatialReference sRef = SpatialReference.FromID("epsg:" + cmbEpsg.SelectedItem.ToString());

            if (sRef == null)
            {
                return;
            }

            IEnvelope extent = _metadata.GetEPSGEnvelope((int)cmbEpsg.SelectedItem);

            if (extent == null)
            {
                return;
            }

            double width  = extent.Width;
            double height = extent.Height;

            double dpu = 1.0;

            if (sRef.SpatialParameters.IsGeographic)
            {
                GeoUnitConverter converter = new GeoUnitConverter();
                dpu = converter.Convert(1.0, GeoUnits.Meters, GeoUnits.DecimalDegrees);
            }

            foreach (double scale in _metadata.Scales)
            {
                double tileWidth  = (double)_metadata.TileWidth * (double)scale / (96.0 / 0.0254);
                double tileHeight = (double)_metadata.TileHeight * (double)scale / (96.0 / 0.0254);

                tileWidth  *= dpu;
                tileHeight *= dpu;

                int tx = (int)Math.Floor(width / tileWidth) + 1;
                int ty = (int)Math.Floor(height / tileHeight) + 1;

                lstScales.Items.Add(new ListViewItem(new string[] { scale.ToString(_nhi), ty.ToString(), tx.ToString(), (tx * ty).ToString() }));
                lstScales.Items[lstScales.Items.Count - 1].Checked = true;
            }

            if (!Envelope.IsNull(this.CurrentExtent) &&
                cmbEpsg.SelectedItem != null)
            {
                ISpatialReference oldSRef = SpatialReference.FromID(lblEpsg.Text.Replace("(", "").Replace(")", ""));
                ISpatialReference newSRef = SpatialReference.FromID("epsg:" + cmbEpsg.SelectedItem.ToString());

                IGeometry geom = GeometricTransformer.Transform2D(this.CurrentExtent, oldSRef, newSRef);
                if (geom != null)
                {
                    this.CurrentExtent = geom.Envelope;
                }
            }
            lblEpsg.Text = "(EPSG:" + (cmbEpsg.SelectedItem != null ? cmbEpsg.SelectedItem.ToString() : "0") + ")";
        }
Example #22
0
        public void OnEvent(object MapEvent)
        {
            if (!(MapEvent is MapEvent))
            {
                return;
            }
            IMap map = ((MapEvent)MapEvent).Map;

            bool firstDataset = (map[0] == null);

            List <ExplorerDialogFilter> filters = new List <ExplorerDialogFilter>();

            filters.Add(new OpenDataFilter());

            ExplorerDialog dlg = new ExplorerDialog("Add data...", filters, true);

            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                List <IDataset> datasets = dlg.Datasets;


                FormDatasetProperties datasetProps = new FormDatasetProperties(datasets);
                try
                {
                    if (((MapEvent)MapEvent).UserData == null)
                    {
                        if (datasetProps.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                        {
                            return;
                        }
                    }
                }
                catch  // Kann ObjectDisposed Exception werfen...
                {
                    return;
                }


                Envelope env = null;
                foreach (ILayer layer in datasetProps.Layers)
                {
                    ISpatialReference sRef     = null;
                    IEnvelope         classEnv = null;
                    if (layer is IFeatureLayer && ((IFeatureLayer)layer).FeatureClass != null && ((IFeatureLayer)layer).FeatureClass.Envelope != null)
                    {
                        sRef     = ((IFeatureLayer)layer).FeatureClass.SpatialReference;
                        classEnv = ((IFeatureLayer)layer).FeatureClass.Envelope;
                    }
                    else if (layer is IRasterLayer && ((IRasterLayer)layer).RasterClass != null && ((IRasterLayer)layer).RasterClass.Polygon != null && ((IRasterLayer)layer).RasterClass.Polygon.Envelope != null)
                    {
                        sRef     = ((IRasterLayer)layer).RasterClass.SpatialReference;
                        classEnv = ((IRasterLayer)layer).RasterClass.Polygon.Envelope;
                    }
                    else if (layer is IWebServiceLayer && ((IWebServiceLayer)layer).WebServiceClass != null && ((IWebServiceLayer)layer).WebServiceClass.Envelope != null)
                    {
                        sRef     = ((IWebServiceLayer)layer).WebServiceClass.SpatialReference;
                        classEnv = ((IWebServiceLayer)layer).WebServiceClass.Envelope;
                    }

                    if (classEnv != null)
                    {
                        if (sRef != null && !sRef.Equals(map.Display.SpatialReference))
                        {
                            bool found = false;
                            foreach (string p in map.Display.SpatialReference.Parameters)
                            {
                                if (p.ToLower().Trim() == "+nadgrids=@null")
                                {
                                    found = false;
                                }
                            }
                            if (found)
                            {
                                classEnv = null;
                            }
                            else
                            {
                                IGeometry geom = GeometricTransformer.Transform2D(classEnv.ToPolygon(0), sRef, map.Display.SpatialReference);
                                if (geom != null)
                                {
                                    classEnv = geom.Envelope;
                                }
                                else
                                {
                                    classEnv = null;
                                }
                            }
                        }
                        if (classEnv != null)
                        {
                            if (env == null)
                            {
                                env = new Envelope(classEnv);
                            }
                            else
                            {
                                env.Union(classEnv);
                            }
                        }
                    }

                    map.AddLayer(layer);
                }
                //map.AddDataset(dataset, 0);


                if (env != null && map.Display != null)
                {
                    if (firstDataset)
                    {
                        map.Display.Limit = env;
                        map.Display.ZoomTo(env);
                    }
                    else
                    {
                        IEnvelope limit = map.Display.Limit;
                        limit.Union(env);
                        map.Display.Limit = limit;
                    }
                }
                ((MapEvent)MapEvent).drawPhase  = DrawPhase.All;
                ((MapEvent)MapEvent).refreshMap = true;
            }
        }
Example #23
0
        static private Item ParseFeature(string metaId, string category, IFeature feature, Item proto, bool useGeometry, GeometricTransformer transformer, ImportConfig.FeatureClassDefinition featureClassDef)
        {
            var replace = featureClassDef.Replacements;

            var result = new Item();

            string oid = feature.OID.ToString();

            if (feature.OID <= 0 && !String.IsNullOrWhiteSpace(featureClassDef.ObjectOidField))
            {
                var idFieldValue = feature.FindField(featureClassDef.ObjectOidField);
                if (idFieldValue != null)
                {
                    oid = idFieldValue.Value?.ToString();
                }
            }

            result.Id            = metaId + "." + oid;
            result.SuggestedText = ParseFeatureField(feature, proto.SuggestedText);
            result.SubText       = ParseFeatureField(feature, proto.SubText);
            result.ThumbnailUrl  = ParseFeatureField(feature, proto.ThumbnailUrl);
            result.Category      = category;

            if (replace != null)
            {
                foreach (var r in replace)
                {
                    result.SuggestedText = result.SuggestedText?.Replace(r.From, r.To);
                    result.SubText       = result.SubText?.Replace(r.From, r.To);
                }
            }

            if (useGeometry == true && feature.Shape != null)
            {
                IGeometry shape = feature.Shape;

                if (shape is IPoint)
                {
                    IPoint point = (IPoint)transformer.Transform2D(feature.Shape);
                    result.Geo = new Nest.GeoLocation(point.Y, point.X);
                }
                else if (shape is IPolyline)
                {
                    IEnvelope env = shape.Envelope;
                    if (env != null)
                    {
                        IPoint point = Algorithm.PolylinePoint((IPolyline)shape, ((IPolyline)shape).Length / 2.0);

                        if (point != null)
                        {
                            point      = (IPoint)transformer.Transform2D(point);
                            result.Geo = new Nest.GeoLocation(point.Y, point.X);
                        }

                        result.BBox = GetBBox(env, transformer);
                    }
                }
                else if (shape is IPolygon)
                {
                    IEnvelope env = shape.Envelope;
                    if (env != null)
                    {
                        var points = Algorithm.OrderPoints(Algorithm.PolygonLabelPoints((IPolygon)shape), env.Center);
                        if (points != null && points.PointCount > 0)
                        {
                            IPoint point = (IPoint)transformer.Transform2D(points[0]);
                            result.Geo = new Nest.GeoLocation(point.Y, point.X);
                        }

                        result.BBox = GetBBox(env, transformer);
                    }
                }
            }

            return(result);
        }
Example #24
0
        public ICursor PointQuery(gView.Framework.Carto.IDisplay display, gView.Framework.Geometry.IPoint point, ISpatialReference sRef, IUserData userdata)
        {
            if (display == null || point == null)
            {
                return(null);
            }

            IEnvelope dispEnvelope = display.Envelope;

            if (sRef != null)
            {
                ISpatialReference mySRef = SpatialReference.FromID(_srs.Srs[_srs.SRSIndex]);
                if (mySRef != null && !mySRef.Equals(sRef))
                {
                    // TODO:
                    // Stimmt net ganz, eigentlich wird beim Projezieren aus dem
                    // Envelope ein Polygon, auch der Punkt, der als X-Pixel, Y-Pixel
                    // übergeben wird, sollte sich ändern...
                    // --> World2Image stimmt nicht 100%
                    //
                    dispEnvelope = GeometricTransformer.Transform2D(dispEnvelope, sRef, mySRef).Envelope;
                }
            }
            double x = point.X, y = point.Y;

            display.World2Image(ref x, ref y);

            StringBuilder request = new StringBuilder("VERSION=1.1.1&REQUEST=GetFeatureInfo");

            request.Append("&QUERY_LAYERS=" + this.Name);
            request.Append("&QUERYLAYERS=" + this.Name);
            request.Append("&LAYERS=" + this.Name);
            //request.Append("&LAYERS=" + this.Name);
            request.Append("&EXCEPTIONS=" + _exceptions.Formats[0]);
            request.Append("&SRS=" + _srs.Srs[_srs.SRSIndex]);
            request.Append("&WIDTH=" + display.iWidth);
            request.Append("&HEIGHT=" + display.iHeight);
            request.Append("&INFOFORMAT=" + _getFeatureInfo.Formats[_getFeatureInfo.FormatIndex]);
            request.Append("&INFO_FORMAT=" + _getFeatureInfo.Formats[_getFeatureInfo.FormatIndex]);
            request.Append("&BBOX=" + dispEnvelope.minx.ToString(_nhi) + "," +
                           dispEnvelope.miny.ToString(_nhi) + "," +
                           dispEnvelope.maxx.ToString(_nhi) + "," +
                           dispEnvelope.maxy.ToString(_nhi));
            request.Append("&X=" + (int)x);
            request.Append("&Y=" + (int)y);

            string response;

            if (_getFeatureInfo.Formats[_getFeatureInfo.FormatIndex].ToLower().StartsWith("xsl/"))
            {
                return(new UrlCursor(WMSDataset.Append2Url(_getFeatureInfo.Get_OnlineResource, request.ToString())));
            }
            else
            {
                switch (_getFeatureInfo.Formats[_getFeatureInfo.FormatIndex].ToLower())
                {
                case "text/plain":
                    response = WebFunctions.HttpSendRequest(WMSDataset.Append2Url(_getFeatureInfo.Get_OnlineResource, request.ToString()));
                    return(new TextCursor(response));

                case "text/html":
                    return(new UrlCursor(WMSDataset.Append2Url(_getFeatureInfo.Get_OnlineResource, request.ToString())));

                case "text/xml":
                    response = WebFunctions.HttpSendRequest(WMSDataset.Append2Url(_getFeatureInfo.Get_OnlineResource, request.ToString()));
                    return(new RowCursor(Xml2Rows(response)));

                case "application/vnd.ogc.gml":
                    response = WebFunctions.HttpSendRequest(WMSDataset.Append2Url(_getFeatureInfo.Get_OnlineResource, request.ToString()));
                    return(new RowCursor(Gml2Rows(response)));
                }
            }
            return(null);
        }
Example #25
0
        public bool MapRequest(gView.Framework.Carto.IDisplay display)
        {
            if (_srs == null)
            {
                return(false);
            }

            if (!_dataset.IsOpened)
            {
                if (!_dataset.Open())
                {
                    return(false);
                }
            }

            List <IWebServiceTheme> themes = Themes;

            if (themes == null)
            {
                return(false);
            }

            #region Check for visible Layers
            bool visFound = false;
            foreach (IWebServiceTheme theme in themes)
            {
                if (!theme.Visible)
                {
                    continue;
                }
                if (theme.MinimumScale > 1 && theme.MinimumScale > display.mapScale)
                {
                    continue;
                }
                if (theme.MaximumScale > 1 && theme.MaximumScale < display.mapScale)
                {
                    continue;
                }

                visFound = true;
                break;
            }
            if (!visFound)
            {
                if (_image != null)
                {
                    _image.Dispose();
                    _image = null;
                }
                return(true);
            }
            #endregion

            int iWidth  = display.iWidth;
            int iHeight = display.iHeight;

            if (BeforeMapRequest != null)
            {
                ISpatialReference sRef = this.SpatialReference;
                BeforeMapRequest(this, display, ref sRef, ref iWidth, ref iHeight);
                if (sRef != null && sRef.Name.ToLower() != this.SRSCode.ToLower())
                {
                    this.SRSCode = sRef.Name;
                }
            }

            IEnvelope displayEnv = display.Envelope;

            if (display.SpatialReference != null && !display.SpatialReference.Equals(this.SpatialReference))
            {
                displayEnv = GeometricTransformer.Transform2D(displayEnv, display.SpatialReference, this.SpatialReference).Envelope;
                iHeight    = (int)((displayEnv.Height / displayEnv.Width) * iWidth);
            }

            StyledLayerDescriptorWriter sldWriter = null;
            StringBuilder request = new StringBuilder("VERSION=1.1.1&REQUEST=GetMap");
            StringBuilder layers = new StringBuilder(), styles = new StringBuilder();
            foreach (IWebServiceTheme theme in themes)
            {
                if (!theme.Visible || theme.Locked ||
                    (!(theme.Class is WMSThemeClass) &&
                     !(theme.Class is WFSFeatureClass)))
                {
                    continue;
                }

                if (layers.Length > 0)
                {
                    layers.Append(",");
                    styles.Append(",");
                }
                layers.Append(theme.Class.Name);
                if (theme.Class is IWMSStyle)
                {
                    styles.Append(((IWMSStyle)theme.Class).Style);
                }
                if (theme.FeatureRenderer != null &&
                    _userDefinedSymbolization.SupportSLD &&
                    _userDefinedSymbolization.UserStyle)
                {
                    SLDRenderer sldRenderer = null;
                    if (theme.FeatureRenderer is SLDRenderer)
                    {
                        sldRenderer = (SLDRenderer)theme.FeatureRenderer;
                    }
                    else
                    {
                        //if (theme.FilterQuery is ISpatialFilter)
                        //{
                        //    IGeometry pGeometry = GeometricTransformer.Transform2D(
                        //        ((ISpatialFilter)theme.FilterQuery).Geometry,
                        //        display.SpatialReference,
                        //        this.SpatialReference);

                        //    IGeometry oGeometry = ((ISpatialFilter)theme.FilterQuery).Geometry;
                        //    ((ISpatialFilter)theme.FilterQuery).Geometry = pGeometry;
                        //    sldRenderer = new SLDRenderer(theme);
                        //    ((ISpatialFilter)theme.FilterQuery).Geometry = oGeometry;
                        //}
                        //else
                        {
                            sldRenderer = new SLDRenderer(theme);
                            if (display.SpatialReference != null)
                            {
                                sldRenderer.SetDefaultSrsName(display.SpatialReference.Name);
                            }
                        }
                    }
                    if (sldWriter == null)
                    {
                        sldWriter = new StyledLayerDescriptorWriter();
                    }

                    sldWriter.WriteNamedLayer(theme.Class.Name, sldRenderer);
                }
            }
            request.Append("&LAYERS=" + layers.ToString());
            if (sldWriter != null)
            {
                string sld = sldWriter.ToLineString();
                if (!_use_SLD_BODY && !string.IsNullOrEmpty(MapServerConfig.DefaultOutputPath))
                {
                    string       sldFilename = "style_" + Guid.NewGuid().ToString("N") + ".sld";
                    StreamWriter sw          = new StreamWriter(MapServerConfig.DefaultOutputPath + @"\" + sldFilename);
                    sw.WriteLine(sldWriter.ToString());
                    sw.Close();

                    request.Append("&SLD=" + MapServerConfig.DefaultOutputUrl + "/" + sldFilename);
                }
                else
                {
                    request.Append("&SLD_BODY=" + sld.Replace("#", "%23"));
                }
            }
            else
            {
                request.Append("&STYLES=" + styles.ToString());
            }
            if (_exceptions != null && _exceptions.Formats.Count > 0)
            {
                request.Append("&EXCEPTIONS=" + _exceptions.Formats[0]);
            }
            request.Append("&SRS=" + _srs.Srs[_srs.SRSIndex]);
            request.Append("&WIDTH=" + iWidth);
            request.Append("&HEIGHT=" + iHeight);
            request.Append("&FORMAT=" + _getMap.Formats[_getMap.FormatIndex]);
            request.Append("&BBOX=" +
                           displayEnv.minx.ToString(_nhi) + "," +
                           displayEnv.miny.ToString(_nhi) + "," +
                           displayEnv.maxx.ToString(_nhi) + "," +
                           displayEnv.maxy.ToString(_nhi));
            //request.Append("&BGCOLOR=FFFFFF");
            request.Append("&TRANSPARENT=TRUE");

            if (_image != null)
            {
                _image.Dispose();
                _image = null;
            }
            System.Drawing.Bitmap bm = null;
            //if (_getMap.Post_OnlineResource != String.Empty && sldWriter != null)
            //{
            //    //bm = WebFunctions.DownloadImage(WMSDataset.Append2Url(_getMap.Post_OnlineResource, request.ToString() + "&SLD="),
            //    //    UTF8Encoding.UTF8.GetBytes(sldWriter.ToString()));
            //    bm = WebFunctions.DownloadImage(_getMap.Post_OnlineResource,
            //        UTF8Encoding.UTF8.GetBytes(request.ToString()));
            //}
            //else
            {
#if (DEBUG)
                gView.Framework.system.Logger.LogDebug("Start WMS DownloadImage");
#endif
                string url = WMSDataset.Append2Url(_getMap.Get_OnlineResource, request.ToString());
                try
                {
                    bm = WebFunctions.DownloadImage(url,
                                                    ConfigTextStream.ExtractValue(_dataset._connectionString, "usr"),
                                                    ConfigTextStream.ExtractValue(_dataset._connectionString, "pwd"));
                }
                catch (Exception ex)
                {
                    WMSClass.ErrorLog(display.Map as IServiceRequestContext, "MapRequest", url, ex);
                    return(false);
                }
#if (DEBUG)
                gView.Framework.system.Logger.LogDebug("WMS DownloadImage Finished");
#endif
            }
            if (bm != null)
            {
                _image                  = new GeorefBitmap(bm);
                _image.Envelope         = displayEnv;
                _image.SpatialReference = this.SpatialReference;

                if (AfterMapRequest != null)
                {
                    AfterMapRequest(this, display, _image);
                }
            }
            return(_image != null);
        }
Example #26
0
        public OgcSpatialFeatureCursor(OgcSpatialFeatureclass fc, IQueryFilter filter)
            : base((fc != null) ? fc.SpatialReference : null,
                   (filter != null) ? filter.FeatureSpatialReference : null)
        {
            if (fc == null || fc.Dataset == null)
            {
                return;
            }

            _idField = fc.IDFieldName;
            if (filter is ISpatialFilter)
            {
                _spatialfilter = (ISpatialFilter)filter;
            }

            try
            {
                if (fc.SpatialReference != null &&
                    filter is ISpatialFilter &&
                    ((ISpatialFilter)filter).FilterSpatialReference != null &&
                    !((ISpatialFilter)filter).FilterSpatialReference.Equals(fc.SpatialReference))
                {
                    filter = (ISpatialFilter)filter.Clone();

                    ((ISpatialFilter)filter).Geometry =
                        GeometricTransformer.Transform2D(((ISpatialFilter)filter).Geometry,
                                                         ((ISpatialFilter)filter).FilterSpatialReference,
                                                         fc.SpatialReference);
                    ((ISpatialFilter)filter).FilterSpatialReference = null;
                    if (((ISpatialFilter)filter).SpatialRelation == spatialRelation.SpatialRelationMapEnvelopeIntersects &&
                        ((ISpatialFilter)filter).Geometry != null)
                    {
                        ((ISpatialFilter)filter).Geometry = ((ISpatialFilter)filter).Geometry.Envelope;
                    }

                    _spatialfilter = (ISpatialFilter)filter;
                }
                DbCommand command = ((OgcSpatialDataset)fc.Dataset).SelectCommand(
                    fc, filter, out _shapeField);
                if (command == null)
                {
                    return;
                }

                _conn = ((OgcSpatialDataset)fc.Dataset).ProviderFactory.CreateConnection();
                _conn.ConnectionString = fc.Dataset.ConnectionString;

                command.Connection = _conn;

                if (_conn.State != ConnectionState.Closed)
                {
                    try
                    {
                        _conn.Close();
                    }
                    catch { }
                }
                _conn.Open();
                //command.Prepare();

                _reader = command.ExecuteReader();
            }
            catch (Exception ex)
            {
                if (_fc != null)
                {
                    _fc.LastException = ex;
                }

                if (_conn != null && _conn.State != ConnectionState.Closed)
                {
                    _conn.Close();
                    _conn = null;
                }
            }
        }