Esempio n. 1
0
    public void LoadFile(string file_path, Canvas canvas)
    {
        if (!System.IO.File.Exists(file_path))
        {
            return;
        }

        m_UTM = m_Converter.LatLngToUtm(m_Latitude, m_Longitude);

        System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

        XDocument doc = XDocument.Load(file_path);

        double minlat, maxlat, minlon, maxlon;

        minlat = minlon = double.MaxValue;
        maxlat = maxlon = double.MinValue;

        foreach (var bound in doc.Root.Elements("bounds"))
        {
            minlat = Math.Min(minlat, double.Parse(bound.Attribute("minlat").Value));
            maxlat = Math.Max(maxlat, double.Parse(bound.Attribute("maxlat").Value));
            minlon = Math.Min(minlon, double.Parse(bound.Attribute("minlon").Value));
            maxlon = Math.Max(maxlon, double.Parse(bound.Attribute("maxlon").Value));
        }

        m_Longitude = (minlon + maxlon) * 0.5;
        m_Latitude  = (minlat + maxlat) * 0.5;

        canvas.Width  = m_Converter.LatLngToUtm(m_Latitude, maxlon).Easting - m_Converter.LatLngToUtm(m_Latitude, minlon).Easting;
        canvas.Height = m_Converter.LatLngToUtm(maxlat, m_Longitude).Northing - m_Converter.LatLngToUtm(minlat, m_Longitude).Northing;

        m_NodeGeoLocs = new Dictionary <long, LatLngUTMConverter.UTMResult>();

        foreach (var node in doc.Root.Elements("node"))
        {
            if (node.Attribute("lon") != null && node.Attribute("lat") != null)
            {
                double lon = double.Parse(node.Attribute("lon").Value);
                double lat = double.Parse(node.Attribute("lat").Value);
                LatLngUTMConverter.UTMResult geoloc = m_Converter.LatLngToUtm(lat, lon);
                m_NodeGeoLocs[long.Parse(node.Attribute("id").Value)] = geoloc;
            }
        }

        CreateAreas(doc, canvas);
        CreateRoads(doc, canvas);
        CreateBuildings(doc, canvas);
    }
    public List <Borehole> getBoreholes(Location currentLocation, double radius)
    {
        List <Borehole> boreholes = null;

        /*
         * pointid = Id i database - Guid
         * pointno = punkt nummer - Guid
         * publicno = DGU nummer - String
         * PointType = punkttype - String - Table: PointTypes
         * Purpose = Formål - String - Table: PointPurposes
         * Projection1 = Primær Projektion: EPSG - Integer - Table: Projections
         * Projection2
         * X1 = Primær X koordinat : float
         * Y1 = Primær Y koordinat : float
         * Z1 = primær z koordinat - Reference Niveau : float
         * ElevationMethod1 = Primær kote metode  - String - Table: PointElevationMethods
         * CoordinateQuality1 = Primær koordinat kvalitet - String - Table: Pointcoordinatequalities
         * CoordinateMethod1 = Primær koordinat metode - String - Table: Pointcoordinatemethods
         * VerticalRefId1 - Højdesystem 1 - String - Table: VerticalRefs
         * ZDVR90 - DVR90 - Double
         * Top - Dybde til top af boring - float
         * Bottom - Dybde til bund af boring [m] - float
         * JupiterId - JupiterId - Int - Check om allerede har data?
         */
        radius = radius * 100000;
        LatLngUTMConverter latLngUTMConverter = new LatLngUTMConverter("EUREF89");

        LatLngUTMConverter.UTMResult utmResult = latLngUTMConverter.convertLatLngToUtm(currentLocation.X, currentLocation.Y);
        //Debug.Log(utmResult.ToString());
        //Debug.Log("Radius:" + radius);
        String sql = "select PointNo, PublicNo, Purpose, X1, Y1, CoordinateMethod1, CoordinateQuality1, Z1, ZDVR90 from points" +
                     " WHERE X1 >= " + (utmResult.Easting - radius).ToString(CultureInfo.InvariantCulture) +
                     " AND X1 <= " + (utmResult.Easting + radius).ToString(CultureInfo.InvariantCulture) +
                     " AND Y1 >= " + (utmResult.Northing - radius).ToString(CultureInfo.InvariantCulture) +
                     " AND Y1 <= " + (utmResult.Northing + radius).ToString(CultureInfo.InvariantCulture);

        Debug.Log("GeoGis Boringer SQL: " + sql);

        String  errMessage = null;
        DataSet dataset    = client.GetDS(this.GEOGIS_DBNAME, this.GEOGIS_USERNAME, this.GEOGIS_PASSWORD, sql, ref errMessage);

        bool allGood = false;

        if (errMessage == null)
        {
            allGood = true;
        }
        else if (errMessage != null)
        {
            if (errMessage == "")
            {
                allGood = true;
            }
            else
            {
                Debug.Log("ErrMessage: " + errMessage);
            }
        }
        if (allGood)
        {
            boreholes = new List <Borehole>();
            foreach (DataTable table in dataset.Tables)
            {
                String[] columnNames = new String[table.Columns.Count];
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    columnNames[i] = table.Columns[i].ColumnName;
                    //Debug.Log(table.Columns[i].ColumnName);
                }

                foreach (System.Data.DataRow row in table.Rows)
                {
                    object[] itemArray            = row.ItemArray;
                    Borehole borehole             = new Borehole();
                    String   pointNo              = null;
                    String   publicNo             = null;
                    float?   latitude             = null;
                    float?   longitude            = null;
                    String   locationQuality_Code = null;
                    String   locationMethod_Code  = null;
                    for (int i = 0; i < itemArray.Length; i++)
                    {
                        if (!(itemArray[i] is DBNull))
                        {
                            switch (columnNames[i])
                            {
                            case "PointNo":
                                pointNo = Convert.ToString(itemArray[i]);
                                break;

                            case "PublicNo":
                                publicNo = Convert.ToString(itemArray[i]);
                                break;

                            case "X1":
                                latitude = Convert.ToSingle(itemArray[i]);
                                break;

                            case "Y1":
                                longitude = Convert.ToSingle(itemArray[i]);
                                break;

                            case "Z1":
                                borehole.ReferencePoint = Convert.ToSingle(itemArray[i]);
                                break;

                            case "ZDVR90":
                                borehole.ReferencePointKote = Convert.ToSingle(itemArray[i]);
                                break;

                            case "CoordinateQuality1":
                                locationQuality_Code = Convert.ToString(itemArray[i]);
                                break;

                            case "CoordinateMethod1":
                                locationMethod_Code = Convert.ToString(itemArray[i]);
                                break;

                            case "Purpose":
                                borehole.BoreholeType = mediatorDatabase.getBoreholeType(Convert.ToString(itemArray[i]));
                                break;

                            default:
                                Debug.Log("Unidentified Column!");
                                break;
                            }
                        }
                    }

                    borehole.BoreholeNo = publicNo != null ? publicNo : pointNo;

                    if (latitude != null && longitude != null)
                    {
                        borehole.Location = new Location((float)latitude, (float)longitude);

                        if (locationQuality_Code != null)
                        {
                            borehole.Location.LocationQuality = mediatorDatabase.getLocationQuality(locationQuality_Code);
                        }
                        if (locationMethod_Code != null)
                        {
                            borehole.Location.LocationMethod = mediatorDatabase.getLocationMethod(locationMethod_Code);
                        }
                    }
                    boreholes.Add(borehole);
                }
            }
        }
        return(boreholes);
    }