예제 #1
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Enter your Location");
            //string location = Console.ReadLine();
            string location = "Port Louis";

            if (!string.IsNullOrEmpty(location))
            {
                GeoLocationClient proxy = new GeoLocationClient("tcpEP");

                GeoLocationData data = proxy.GetCoordinates(location);
                if (data != null)
                {
                    Console.WriteLine(data.Name);
                    Console.WriteLine(string.Concat("Latitude: ", data.Latitude));
                    Console.WriteLine(string.Concat("Longitude: ", data.Longitude));
                }
            }
            else
            {
                Console.WriteLine("No location entered");
            }
            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
        }
예제 #2
0
        public IList <IVersionAgnostic> getCsvData(TableVersion.Value tableVersion, string searchName, Tail tail, Ear ear, Nose nose,
                                                   DateAndTime dateAndTime, GeoLocationData latitudeData, GeoLocationData longitudeData)
        {
            var dbContext = new Model1();
            var builder   = new Builder();

            IQueryable <IVersionAgnostic> csvData = null;

            if (tableVersion == TableVersion.Value.Version1)
            {
                csvData = dbContext.csvWithDataVersion1.AsQueryable();
            }
            else
            {
                csvData = dbContext.csvWithDataVersion2.AsQueryable();
            }

            csvData = builder.addNameFilter(csvData, searchName);
            csvData = builder.tailHighFilter(csvData, tail.highData);
            csvData = builder.tailLowFilter(csvData, tail.lowData);
            csvData = builder.earHighFilter(csvData, ear.highData);
            csvData = builder.earLowFilter(csvData, ear.lowData);
            csvData = builder.noseHighFilter(csvData, nose.highData);
            csvData = builder.noseLowFilter(csvData, nose.lowData);
            csvData = builder.DateFilter(csvData, dateAndTime);
            csvData = builder.LatitudeFilter(csvData, latitudeData);
            csvData = builder.LongitudeFilter(csvData, longitudeData);
            return(csvData.ToList());
        }
 public DataTable getDataTable(TableVersion.Value tableVersion, string searchName, Tail tail, Ear ear, Nose nose,
                               DateAndTime dateAndTime, GeoLocationData latitudeData, GeoLocationData longitudeData)
 {
     return(dataTableFactory.getDataTable(
                tableVersion,
                getCsvData(tableVersion, searchName, tail, ear, nose, dateAndTime, latitudeData, longitudeData),
                csvDataProvider.getCsvColumnNames(tableVersion)));
 }
 public void generateCsv(TableVersion.Value tableVersion, string fileName, string searchName, Tail tail, Ear ear, Nose nose,
                         DateAndTime dateAndTime, GeoLocationData latitudeData, GeoLocationData longitudeData)
 {
     csvDataToCsvTransformer.writeDataToCsv(
         tableVersion,
         getCsvData(tableVersion, searchName, tail, ear, nose, dateAndTime, latitudeData, longitudeData),
         fileName,
         csvDataProvider.getCsvColumnNames(tableVersion));
 }
예제 #5
0
        public Coordinates GetCoordinates()
        {
            if (!String.IsNullOrWhiteSpace(GeoLocationData))
            {
                string[] values = GeoLocationData.Split(char.Parse(","));

                if (values != null && values.Count() == 2)
                {
                    var coordinates = new Coordinates();
                    coordinates.Latitude  = double.Parse(values[0]);
                    coordinates.Longitude = double.Parse(values[1]);

                    return(coordinates);
                }
            }

            return(null);
        }
        public GeoLocationData GetCoordinates(string name)
        {
            GeoLocationData        result = null;
            IGeoLocationRepository geoLocationRepository = _geoLocationRepository ?? new GeoLocationRepository();

            var geolocation = geoLocationRepository.GetCoordinates(name);


            if (geolocation != null)
            {
                result = new GeoLocationData
                {
                    Name      = geolocation.Name,
                    Latitude  = geolocation.Latitude,
                    Longitude = geolocation.Longitude
                };
            }

            return(result);
        }
        /// <summary>
        /// create map image
        /// not working currently
        /// </summary>
        /// <param name="data"></param>
        private void createMapImage(GeoLocationData data)
        {
            var doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;

            if (doc == null)
            {
                return;
            }
            var db = doc.Database;
            var ed = doc.Editor;

            //now get an image

            var first = new Point2d(261290.0000, 270952.5000);
            //second corner
            var second = new Point2d(568732.0000, 76776.5000);

            ObjectId           giId    = ObjectId.Null;
            ObjectEventHandler handler =
                (s, e) =>
            {
                if (e.DBObject is GeomapImage)
                {
                    giId = e.DBObject.ObjectId;
                    ed.WriteMessage("\n map image objectid: " + giId);
                }
            };

            // Simply call the GEOMAPIMAGE command with the two points
            db.ObjectAppended += handler;
            ed.Command("GEOMAPIMAGE", "V");
            db.ObjectAppended -= handler;

            if (giId == ObjectId.Null)
            {
                return;
            }

            // Open the entity and change some values
            try
            {
                using (var tr = doc.TransactionManager.StartTransaction())
                {
                    // Get each object and check if it's a GeomapImage
                    var gi =
                        tr.GetObject(giId, OpenMode.ForWrite) as GeomapImage;
                    if (gi != null)
                    {
                        // Let's adjust the brightmess/contrast/fade of the
                        // GeomapImage

                        gi.Brightness = 50;
                        gi.Contrast   = 15;
                        gi.Fade       = 0;

                        // And make sure it's at the right resolution and
                        // shows both aerial and road information

                        gi.Resolution = GeomapResolution.Optimal;
                        gi.MapType    = GeomapType.Road;

                        gi.UpdateMapImage(true);

                        //keep map only
                        //data.EraseFromDb();
                    }

                    tr.Commit();
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception)
            {
                ed.WriteMessage(
                    "\nUnable to update geomap image entity." +
                    "\nPlease check your internet connectivity and call " +
                    "GEOMAPIMAGEUPDATE."
                    );
            }
        }
        /// <summary>
        /// place the real GEO map underlay
        /// </summary>
        /// <param name="centerPt"></param>
        /// <param name="sourceMapCorners"></param>
        private void buildGEOImage(MapPointCls centerPt, MapPointCls[] sourceMapCorners)
        {
            var doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;

            if (doc == null)
            {
                return;
            }
            var db = doc.Database;
            var ed = doc.Editor;

            double ModelCenterX = HardCoded.ModelCenterX;
            double ModelCenterY = HardCoded.ModelCenterY;


            //GEO location data of the corners
            //the source are two points. calculate the other two points
            //convert them to string

            string[]     oMapCorners = new string[4];
            GEOConverter oGeoC       = new GEOConverter();

            //left top
            DecimalLocation decimalLocation = new DecimalLocation
            {
                Latitude  = (decimal)sourceMapCorners[0].latitude,
                Longitude = (decimal)sourceMapCorners[0].longitude
            };
            DmsLocation dmsLocation = oGeoC.Convert(decimalLocation);

            oMapCorners[0] = dmsLocation.ToString();

            //right top
            decimalLocation = new DecimalLocation
            {
                Latitude  = (decimal)sourceMapCorners[0].latitude,
                Longitude = (decimal)sourceMapCorners[1].longitude
            };
            dmsLocation    = oGeoC.Convert(decimalLocation);
            oMapCorners[1] = dmsLocation.ToString();

            //right bottom
            decimalLocation = new DecimalLocation
            {
                Latitude  = (decimal)sourceMapCorners[1].latitude,
                Longitude = (decimal)sourceMapCorners[1].longitude
            };
            dmsLocation    = oGeoC.Convert(decimalLocation);
            oMapCorners[2] = dmsLocation.ToString();

            //left bottom
            decimalLocation = new DecimalLocation
            {
                Latitude  = (decimal)sourceMapCorners[1].latitude,
                Longitude = (decimal)sourceMapCorners[0].longitude
            };
            dmsLocation    = oGeoC.Convert(decimalLocation);
            oMapCorners[3] = dmsLocation.ToString();


            //hard coded data of corners position in DWG
            CommonPointCls[] oDWGCorners = oHard_Coded_Data.GetDWGCorner();


            //create the text one by one
            using (Transaction acTrans = db.TransactionManager.StartTransaction())
            {
                BlockTable       acBlkTable = acTrans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = acTrans.GetObject(acBlkTable[BlockTableRecord.ModelSpace],
                                                                OpenMode.ForWrite) as BlockTableRecord;

                //place the position of each text
                for (int i = 0; i < oDWGCorners.Count <CommonPointCls>(); i++)
                {
                    DBText dt = new DBText();
                    dt.TextString = oMapCorners[i];

                    switch (i)
                    {
                    case 0:
                        //left top
                        dt.Justify  = AttachmentPoint.BottomMid;
                        dt.Rotation = 45;
                        break;

                    case 1:
                        //right top
                        dt.Justify  = AttachmentPoint.BottomMid;
                        dt.Rotation = -45;
                        break;

                    case 2:
                        //right bottom
                        dt.Justify  = AttachmentPoint.TopMid;
                        dt.Rotation = 45;
                        break;

                    case 3:
                        //left bottom
                        dt.Justify  = AttachmentPoint.TopMid;
                        dt.Rotation = -45;
                        break;
                    }

                    //align with the corner position
                    dt.AlignmentPoint = new Point3d(oDWGCorners[i].x, oDWGCorners[i].y, oDWGCorners[i].z);
                    dt.TransformBy(ed.CurrentUserCoordinateSystem);
                    dt.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(0, 255, 255);

                    modelSpace.AppendEntity(dt);
                    acTrans.AddNewlyCreatedDBObject(dt, true);
                }

                acTrans.Commit();
            }

            //!!!
            return;

            //embed map underlay. not working with Design Automation

            // from
            //http://through-the-interface.typepad.com/through_the_interface/2014/06/attaching-geo-location-data-to-an-autocad-drawing-using-net.html
            try
            {
                var gdId = db.GeoDataObject;
                //if a map data is available
                //will not happen with current drawing template
            }
            catch
            {
                //no GEO data

                var msId = SymbolUtilityServices.GetBlockModelSpaceId(db);

                var data = new GeoLocationData();
                data.BlockTableRecordId = msId;
                data.PostToDb();

                // We're going to define our geolocation in terms of
                // latitude/longitude using the Mercator projection
                // http://en.wikipedia.org/wiki/Mercator_projection

                data.CoordinateSystem  = "WORLD-MERCATOR";
                data.TypeOfCoordinates = TypeOfCoordinates.CoordinateTypeLocal;

                //the two lines will cause GEOMapImage fail! strange!
                //data.HorizontalUnits = UnitsValue.Millimeters;
                //data.VerticalUnits = UnitsValue.Millimeters;

                var geoPt = new Point3d(centerPt.longitude, centerPt.latitude, 0);

                // Transform from a geographic to a modelspace point
                // and add the information to our geolocation data
                var wcsPt = data.TransformFromLonLatAlt(geoPt);
                data.DesignPoint    = new Point3d(ModelCenterX, ModelCenterY, 0);
                data.ReferencePoint = wcsPt;
                data.ScaleFactor    = 7; //? useful?

                ed.Command("_.GEOMAP", "_ROAD");


                // then create the map image
                //createMapImage(data);
            }
        }
예제 #9
0
 private void OnLocationUpdated(GeoLocationData data)
 {
     LocationUpdated?.Invoke(this, new GeoLocationEventArgs(data));
 }
예제 #10
0
        internal IQueryable <IVersionAgnostic> LatitudeFilter(IQueryable <IVersionAgnostic> csvData, GeoLocationData latitudeData)
        {
            if (isValidDataForDoubles(latitudeData.pointInSpace, latitudeData.radiusFromPointInSpace))
            {
                return(csvData);
            }

            double latitude           = Convert.ToDouble(latitudeData.pointInSpace);
            double radiusFromLatitude = Convert.ToDouble(latitudeData.radiusFromPointInSpace);

            double latitudeToBeGreaterThan = latitude - radiusFromLatitude;
            double latitudeToBelessThan    = latitude + radiusFromLatitude;

            return(csvData.Where(x => x.latitude < latitudeToBelessThan && x.latitude > latitudeToBeGreaterThan));
        }
 private IList <IVersionAgnostic> getCsvData(TableVersion.Value tableVersion, string searchName, Tail tail, Ear ear, Nose nose,
                                             DateAndTime dateAndTime, GeoLocationData latitudeData, GeoLocationData longitudeData)
 {
     return(csvDataProvider.getCsvData(tableVersion, searchName, tail, ear, nose,
                                       dateAndTime, latitudeData, longitudeData));
 }