예제 #1
0
        public static Envelope2 <T> EnvelopeFor <T>(IGeometry2 <T> a, IGeometry2 <T> b, IGeometry2 <T> c)
            where T : IEquatable <T>, IComparable <T>
        {
            if (a == null)
            {
                if (b == null)
                {
                    if (c == null)
                    {
                        return(null);
                    }
                    return(c.Envelope);
                }
            }
            else if (b == null)
            {
                if (c == null)
                {
                    return(a.Envelope);
                }
                return(EnvelopeFor <T>(a, c));
            }
            else if (c == null)
            {
                return(EnvelopeFor <T>(a, b));
            }

            Envelope2 <T> envCur = a.Envelope;

            envCur = Envelope2 <T> .Bound(envCur, b.Envelope);

            return(Envelope2 <T> .Bound(envCur, c.Envelope));
        }
예제 #2
0
        public static Envelope2 <T> EnvelopeFor <T>(IEnumerable <IGeometry2 <T> > shapes)
            where T : IEquatable <T>, IComparable <T>
        {
            if (shapes == null)
            {
                return(null);
            }
            IEnumerator <IGeometry2 <T> > en = shapes.GetEnumerator();
            Envelope2 <T> curEnv             = null;

            if (en.MoveNext())
            {
                IGeometry2 <T> cur = en.Current;
                Envelope2 <T>  env = null;
                if (cur != null)
                {
                    env = cur.Envelope;
                }
                curEnv = env;
                while (en.MoveNext())
                {
                    cur = en.Current;
                    if (cur != null)
                    {
                        env = cur.Envelope;
                    }
                    curEnv = Envelope2 <T> .Bound(curEnv, env);
                }
                return(curEnv);
            }
            return(null);
        }
예제 #3
0
 public static JObject ToGeoJson(IGeometry2 <double> geom)
 {
     if (geom is Geometry2Bag <double> )
     {
         return(GeoJsonUtils.ToGeoJson(geom as Geometry2Bag <double>));
     }
     if (geom is PolygonBag2 <double> )
     {
         return(GeoJsonUtils.ToGeoJson(geom as PolygonBag2 <double>));
     }
     if (geom is Polygon2 <double> )
     {
         return(GeoJsonUtils.ToGeoJson(geom as Polygon2 <double>));
     }
     if (geom is Polyline2 <double> )
     {
         return(GeoJsonUtils.ToGeoJson(geom as Polyline2 <double>));
     }
     if (geom is PolylineBag2 <double> )
     {
         return(GeoJsonUtils.ToGeoJson(geom as PolylineBag2 <double>));
     }
     if (geom is Point2 <double> )
     {
         return(GeoJsonUtils.ToGeoJson(geom as Point2 <double>));
     }
     if (geom is PointBag2 <double> )
     {
         return(GeoJsonUtils.ToGeoJson(geom as PointBag2 <double>));
     }
     return((JObject)null);
 }
예제 #4
0
        private static void CreateSitesCsv(CsvDb db, Dictionary <CompoundIdentity, Tuple <int, Site> > siteDict)
        {
            string[] cols = new string[] { "SiteKey", "Name", "Description", "Location", "LocationMark" };

            ITable sites = db.Create("Sites", cols);

            var orderedSites = siteDict.OrderBy(x => x.Value.Item1);

            foreach (var site in orderedSites)
            {
                Site s = site.Value.Item2;
                IRow r = sites.CreateRow();
                r[0] = site.Value.Item1.ToString();
                r[1] = s.Name;
                r[2] = s.Description;
                IGeometry2 <double> geom = s.Location;
                if (geom != null)
                {
                    if (geom is PolygonBag2 <double> )
                    {
                        r[3] = WktUtils.ToWkt(geom as PolygonBag2 <double>).ToString();
                    }
                    else if (geom is Polygon2 <double> )
                    {
                        r[3] = WktUtils.ToWkt(geom as Polygon2 <double>).ToString();
                    }
                    else if (geom is Polyline2 <double> )
                    {
                        r[3] = WktUtils.ToWkt(geom as Polyline2 <double>).ToString();
                    }
                    else if (geom is PolylineBag2 <double> )
                    {
                        r[3] = WktUtils.ToWkt(geom as PolylineBag2 <double>).ToString();
                    }
                    else if (geom is Point2 <double> )
                    {
                        r[3] = WktUtils.ToWkt(geom as Point2 <double>).ToString();
                    }
                }
                else
                {
                    r[3] = "";
                }

                Point2 <double> geom2 = s.LocationMark;
                if (geom2 != null)
                {
                    r[4] = WktUtils.ToWkt(geom2 as Point2 <double>).ToString();
                }
                else
                {
                    r[4] = "";
                }

                sites.AddRow(r);
            }
            sites.Flush();
            return;
        }
예제 #5
0
 public static JObject ToJson(IGeometry2 <double> shape)
 {
     if (shape != null)
     {
         return(GeoJsonUtils.ToGeoJson(shape));
     }
     return(null);
 }
예제 #6
0
 public static Envelope2 <T> EnvelopeFor <T>(Envelope2 <T> env, IGeometry2 <T> p)
     where T : IEquatable <T>, IComparable <T>
 {
     if (env == null)
     {
         if (p == null)
         {
             return(null);
         }
         return(p.Envelope);
     }
     return(Envelope2 <T> .Bound(env, p.Envelope));
 }
예제 #7
0
 public static Geometry2Bag <double> BuildGeometryCollection(PositionSet ps)
 {
     if (ps != null && (ps.GeometryHint == PositionType.GeometryCollection || ps.GeometryHint == PositionType.Unknown))
     {
         List <IGeometry2 <double> > list = new List <IGeometry2 <double> >();
         foreach (Position p in ps.Positions)
         {
             IGeometry2 <double> geometry = null;
             if (p.GeometryHint == PositionType.Point)
             {
                 geometry = BuildPoint(p);
             }
             else if (p.GeometryHint == PositionType.MultiPoint)
             {
                 geometry = BuildMultiPoint(p as PositionSet);
             }
             else if (p.GeometryHint == PositionType.LineString)
             {
                 geometry = BuildLineString(p as PositionSet);
             }
             else if (p.GeometryHint == PositionType.MultiLineString)
             {
                 geometry = BuildMultiLineString(p as PositionSet);
             }
             else if (p.GeometryHint == PositionType.Polygon)
             {
                 geometry = BuildPolygon(p as PositionSet);
             }
             else if (p.GeometryHint == PositionType.MultiPolygon)
             {
                 geometry = BuildMultiPolygon(p as PositionSet);
             }
             if (geometry == null)
             {
                 return(null);
             }
             list.Add(geometry);
         }
         if (list.Count > 0)
         {
             return(factory.ConstructGeometryBag(list));
         }
     }
     return(null);
 }
예제 #8
0
        public static Envelope2 <T> EnvelopeFor <T>(IGeometry2 <T> a, IGeometry2 <T> b)
            where T : IEquatable <T>, IComparable <T>
        {
            if (a == null)
            {
                if (b == null)
                {
                    return(null);
                }
                return(a.Envelope);
            }
            else if (b == null)
            {
                return(a.Envelope);
            }

            return(Envelope2 <T> .Bound(a.Envelope, b.Envelope));
        }
예제 #9
0
    //----------------------------------------------------------------------------------



    public static MultiPatch MaakTrianglesMP()
    {
        MultiPatch          pMultiPatch = new MultiPatch();
        IGeometryCollection pGCol       = (IGeometryCollection)pMultiPatch;
        IPointCollection    pTriangles  = new Triangles();
        IGeometry2          pGeom       = (IGeometry2)pTriangles;
        int nfcs = ImportInArcscene.binReader.ReadInt32();

        for (int i = 1; i <= nfcs * 3; i++)
        {
            double ptx = ImportInArcscene.binReader.ReadSingle();
            double pty = ImportInArcscene.binReader.ReadSingle();
            double ptz = ImportInArcscene.binReader.ReadSingle();
            pTriangles.AddPoint(PuntTransformatie(ptx, pty, ptz), ref _missing, ref _missing);
        }

        pGCol.AddGeometry(pGeom, ref _missing, ref _missing);
        return(pMultiPatch);
    }
예제 #10
0
        /// <summary>
        /// Transforms an Point to a different coordinate system.
        /// </summary>
        /// <param name="inPoint">The Point to be Converted</param>
        /// <param name="inDataCoordinateSystem">The Coordinate System the point is currently in</param>
        /// <param name="inReturnCoordinateSystem">The coordinate System the point is to be returned into</param>
        /// <returns>A transformed point or null.</returns>
        public T ConvertToCoordinateSystem <T>(T inputGeometry, int inDataCoordinateSystem, ISpatialReference destSpatialReference) where T : IGeometry2
        {
            // Create source spatial reference

            ISpatialReferenceFactory2 spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            ISpatialReference         sourceSpatialReference  = spatialReferenceFactory.CreateSpatialReference(inDataCoordinateSystem);

            if (destSpatialReference == null)
            {
                return(inputGeometry);
            }

            //cast T as IGeometry2 and project this.
            IGeometry2 geometry = inputGeometry as IGeometry2;

            if ((inDataCoordinateSystem == 27700) && (destSpatialReference.FactoryCode == 4326))
            {
                IGeoTransformation geoTransformation = spatialReferenceFactory.CreateGeoTransformation(1196) as IGeoTransformation;
                geometry.ProjectEx(destSpatialReference as ISpatialReference, esriTransformDirection.esriTransformForward, geoTransformation, false, 0, 0);
            }
            else if ((inDataCoordinateSystem == 4326) && (destSpatialReference.FactoryCode == 27700))
            {
                IGeoTransformation geoTransformation = spatialReferenceFactory.CreateGeoTransformation(1196) as IGeoTransformation;
                geometry.ProjectEx(destSpatialReference as ISpatialReference, esriTransformDirection.esriTransformReverse, geoTransformation, false, 0, 0);
            }
            else if ((inDataCoordinateSystem == 27700) && (destSpatialReference.FactoryCode == 102113))
            {
                IGeoTransformation          geoTransformation  = spatialReferenceFactory.CreateGeoTransformation(1196) as IGeoTransformation;
                IGeoTransformation          pGeoTrans_B        = spatialReferenceFactory.CreateGeoTransformation(108100) as IGeoTransformation; // ' WGS84 Maj Aux Sphere to WGS84
                ICompositeGeoTransformation pGeoTransComposite = new CompositeGeoTransformationClass() as ICompositeGeoTransformation;
                pGeoTransComposite.Add(esriTransformDirection.esriTransformForward, geoTransformation);                                         // National Grid to Wgs84
                pGeoTransComposite.Add(esriTransformDirection.esriTransformReverse, pGeoTrans_B);                                               // reversed sphere to wgs84
                geometry.ProjectEx(destSpatialReference, esriTransformDirection.esriTransformForward, pGeoTransComposite, false, 0, 0);
            }
            else if ((inDataCoordinateSystem == 102113) && (destSpatialReference.FactoryCode == 27700))
            {
                IGeoTransformation          geoTransformation  = spatialReferenceFactory.CreateGeoTransformation(1196) as IGeoTransformation;
                IGeoTransformation          pGeoTrans_B        = spatialReferenceFactory.CreateGeoTransformation(108100) as IGeoTransformation; // ' WGS84 Maj Aux Sphere to WGS84
                ICompositeGeoTransformation pGeoTransComposite = new CompositeGeoTransformationClass() as ICompositeGeoTransformation;
                pGeoTransComposite.Add(esriTransformDirection.esriTransformForward, pGeoTrans_B);                                               // sphere to wgs84
                pGeoTransComposite.Add(esriTransformDirection.esriTransformReverse, geoTransformation);                                         // National Grid to Wgs84
                geometry.ProjectEx(destSpatialReference, esriTransformDirection.esriTransformForward, pGeoTransComposite, false, 0, 0);
            }
            else if ((inDataCoordinateSystem == 27700) && (destSpatialReference.FactoryCode == 102100))
            {
                IGeoTransformation          geoTransformation  = spatialReferenceFactory.CreateGeoTransformation(1196) as IGeoTransformation;
                IGeoTransformation          pGeoTrans_B        = spatialReferenceFactory.CreateGeoTransformation(108100) as IGeoTransformation; // ' WGS84 Maj Aux Sphere to WGS84
                ICompositeGeoTransformation pGeoTransComposite = new CompositeGeoTransformationClass();
                pGeoTransComposite.Add(esriTransformDirection.esriTransformForward, geoTransformation);                                         // National Grid to Wgs84
                pGeoTransComposite.Add(esriTransformDirection.esriTransformReverse, pGeoTrans_B);                                               // reversed sphere to wgs84
                geometry.ProjectEx(destSpatialReference, esriTransformDirection.esriTransformForward, pGeoTransComposite, false, 0, 0);
            }
            else if ((inDataCoordinateSystem == 102100) && (destSpatialReference.FactoryCode == 27700))
            {
                IGeoTransformation          geoTransformation  = spatialReferenceFactory.CreateGeoTransformation(1196) as IGeoTransformation;
                IGeoTransformation          pGeoTrans_B        = spatialReferenceFactory.CreateGeoTransformation(108100) as IGeoTransformation; // ' WGS84 Maj Aux Sphere to WGS84
                ICompositeGeoTransformation pGeoTransComposite = new CompositeGeoTransformationClass();
                pGeoTransComposite.Add(esriTransformDirection.esriTransformForward, pGeoTrans_B);                                               // sphere to wgs84
                pGeoTransComposite.Add(esriTransformDirection.esriTransformReverse, geoTransformation);                                         // National Grid to Wgs84
                geometry.ProjectEx(destSpatialReference, esriTransformDirection.esriTransformForward, pGeoTransComposite, false, 0, 0);
            }

            else if ((inDataCoordinateSystem == 27700) && (destSpatialReference.FactoryCode == 3857))
            {
                IGeoTransformation          geoTransformation  = spatialReferenceFactory.CreateGeoTransformation(1196) as IGeoTransformation;
                IGeoTransformation          pGeoTrans_B        = spatialReferenceFactory.CreateGeoTransformation(108100) as IGeoTransformation; // ' WGS84 Maj Aux Sphere to WGS84
                ICompositeGeoTransformation pGeoTransComposite = new CompositeGeoTransformationClass();
                pGeoTransComposite.Add(esriTransformDirection.esriTransformForward, geoTransformation);                                         // National Grid to Wgs84
                pGeoTransComposite.Add(esriTransformDirection.esriTransformReverse, pGeoTrans_B);                                               // reversed sphere to wgs84
                geometry.ProjectEx(destSpatialReference, esriTransformDirection.esriTransformForward, pGeoTransComposite, false, 0, 0);
            }
            else if ((inDataCoordinateSystem == 3857) && (destSpatialReference.FactoryCode == 27700))
            {
                IGeoTransformation          geoTransformation  = spatialReferenceFactory.CreateGeoTransformation(1196) as IGeoTransformation;
                IGeoTransformation          pGeoTrans_B        = spatialReferenceFactory.CreateGeoTransformation(108100) as IGeoTransformation; // ' WGS84 Maj Aux Sphere to WGS84
                ICompositeGeoTransformation pGeoTransComposite = new CompositeGeoTransformationClass();
                pGeoTransComposite.Add(esriTransformDirection.esriTransformForward, pGeoTrans_B);                                               // sphere to wgs84
                pGeoTransComposite.Add(esriTransformDirection.esriTransformReverse, geoTransformation);                                         // National Grid to Wgs84
                geometry.ProjectEx(destSpatialReference, esriTransformDirection.esriTransformForward, pGeoTransComposite, false, 0, 0);
            }
            else
            {
                geometry.Project(destSpatialReference as ISpatialReference);
            }

            return(inputGeometry);
        }
예제 #11
0
        private Guid CreateExcelFile(Dictionary <CompoundIdentity, Tuple <int, Site> > siteDict, Dictionary <CompoundIdentity, Tuple <int, SamplingEvent> > eventDict,
                                     Dictionary <CompoundIdentity, Tuple <int, WaterQualityDeployment> > deploymentDict, List <Tuple <int, WaterQualityMeasurement> > measurementList,
                                     Dictionary <CompoundIdentity, Organization> orgDict, Dictionary <CompoundIdentity, FieldTrip> fieldTripDict,
                                     Dictionary <CompoundIdentity, FieldActivity> fieldActivityDict, Dictionary <CompoundIdentity, Project> projectDict)
        {
            IFileStoreProvider provider = FileStoreManager.Instance.GetProvider();

            //Setting up file and Excel Workbook
            FilestoreFile deployFile = provider.MakeTemp(DateTime.UtcNow.AddHours(4));
            XlWorkbook    book       = new XlWorkbook();
            XlWorksheets  sheets     = book.Worksheets;

            //Generating Sampling Event Sheet
            XlSchema    eventSchema = GetSampleEventSchema();
            XlWorksheet eventSheet  = sheets.AddWorksheet("SamplingEvents", XlColor.White, eventSchema);
            XlRows      eventRows   = eventSheet.Rows;

            var orderedEvents = eventDict.OrderBy(x => x.Value.Item1);

            foreach (var evt in orderedEvents)
            {
                string orgName = na;
                if (orgDict.ContainsKey(evt.Value.Item2.PrincipalOrgId))
                {
                    orgName = orgDict[evt.Value.Item2.PrincipalOrgId].Name;
                }
                string ftripName     = na;
                string factivityName = na;
                string projName      = na;
                if (fieldTripDict.ContainsKey(evt.Value.Item2.FieldTripId))
                {
                    FieldTrip ftrip = fieldTripDict[evt.Value.Item2.FieldTripId];
                    ftripName = ftrip.Name;
                    if (fieldActivityDict.ContainsKey(ftrip.FieldActivityId))
                    {
                        FieldActivity factivity = fieldActivityDict[ftrip.FieldActivityId];
                        factivityName = factivity.Name;
                        if (projectDict.ContainsKey(factivity.ProjectId))
                        {
                            projName = projectDict[factivity.ProjectId].Name;
                        }
                    }
                }

                List <string> evtItems = new List <string>();
                evtItems.Add(orgName);
                evtItems.Add(projName);
                evtItems.Add(factivityName);
                evtItems.Add(ftripName);
                evtItems.Add(evt.Value.Item2.Name);
                evtItems.Add(evt.Value.Item1.ToString());
                evtItems.Add(evt.Value.Item2.Description);
                //evtItems.Add(evt.Value.Item2.DateRange.Min.ToString());
                //evtItems.Add(evt.Value.Item2.DateRange.Max.ToString());

                SchemaRowData row = new SchemaRowData(eventSchema, evtItems);
                eventRows.AddRow(row);
            }

            //Generating Deployment/Measurement Sheet
            XlSchema    measSchema = GetDeployMeasurementSchema();
            XlWorksheet measSheet  = sheets.AddWorksheet("WaterQualityMeasurements", XlColor.White, measSchema);
            XlRows      measRows   = measSheet.Rows;

            var orderedMeasurements = measurementList.OrderBy(x => x.Item1);

            foreach (var meas in orderedMeasurements)
            {
                WaterQualityDeployment  deploy      = deploymentDict[meas.Item2.DeploymentId].Item2;
                WaterQualityMeasurement measurement = meas.Item2;
                int eventIndex = eventDict[deploy.SampleEventId].Item1;

                //deploy.SiteId could be a dangling reference
                string siteFK = na;
                if (siteDict.ContainsKey(deploy.SiteId))
                {
                    siteFK = siteDict[deploy.SiteId].Item1.ToString();
                }

                List <string> measItems = new List <string>();
                measItems.Add(meas.Item1.ToString());
                measItems.Add(deploy.Name);
                measItems.Add(deploy.Description);
                measItems.Add(eventIndex.ToString());
                measItems.Add(siteFK);
                measItems.Add(deploy.Range.StartDate.ToString());
                measItems.Add(deploy.Range.EndDate.ToString());
                measItems.Add(measurement.SampleDate.ToString());
                measItems.Add(measurement.SurfaceElevation.ToString());
                measItems.Add(measurement.Temperature.ToString());
                measItems.Add(measurement.pH.ToString());
                measItems.Add(measurement.DissolvedOxygen.ToString());
                measItems.Add(measurement.Conductivity.ToString());
                measItems.Add(measurement.Salinity.ToString());
                measItems.Add(measurement.Velocity.ToString());
                SchemaRowData row = new SchemaRowData(measSchema, measItems);
                measRows.AddRow(row);
            }

            //Generating Site Sheet
            XlSchema    siteSchema = GetSiteSchema();
            XlWorksheet siteSheet  = sheets.AddWorksheet("Sites", XlColor.White, siteSchema);
            XlRows      siteRows   = siteSheet.Rows;

            var orderedSites = siteDict.OrderBy(x => x.Value.Item1);

            foreach (var site in orderedSites)
            {
                Site          s         = site.Value.Item2;
                List <string> siteItems = new List <string>();
                siteItems.Add(site.Value.Item1.ToString());
                siteItems.Add(s.Name);
                siteItems.Add(s.Description);
                IGeometry2 <double> geom = s.Location;
                if (geom != null)
                {
                    if (geom is PolygonBag2 <double> )
                    {
                        siteItems.Add(WktUtils.ToWkt(geom as PolygonBag2 <double>).ToString());
                    }
                    else if (geom is Polygon2 <double> )
                    {
                        siteItems.Add(WktUtils.ToWkt(geom as Polygon2 <double>).ToString());
                    }
                    else if (geom is Polyline2 <double> )
                    {
                        siteItems.Add(WktUtils.ToWkt(geom as Polyline2 <double>).ToString());
                    }
                    else if (geom is PolylineBag2 <double> )
                    {
                        siteItems.Add(WktUtils.ToWkt(geom as PolylineBag2 <double>).ToString());
                    }
                    else if (geom is Point2 <double> )
                    {
                        siteItems.Add(WktUtils.ToWkt(geom as Point2 <double>).ToString());
                    }
                }
                else
                {
                    siteItems.Add("");
                }

                Point2 <double> geom2 = s.LocationMark;
                if (geom2 != null)
                {
                    siteItems.Add(WktUtils.ToWkt(geom2 as Point2 <double>).ToString());
                }
                else
                {
                    siteItems.Add("");
                }

                SchemaRowData row = new SchemaRowData(siteSchema, siteItems);
                siteRows.AddRow(row);
            }

            book.Save(deployFile);
            deployFile.Flush();
            deployFile.Close();
            deployFile.Dispose();

            return(deployFile.FileId);
        }
예제 #12
0
 public static PostgisGeometry ToPGis(IGeometry2 <double> geom)
 {
     if (geom != null)
     {
         if (geom is Point2 <double> )
         {
             return(ToPGis(geom as Point2 <double>));
         }
         else if (geom is LineSegment2 <double> )
         {
             return(ToPGis(geom as LineSegment2 <double>));
         }
         else if (geom is Polygon2 <double> )
         {
             return(ToPGis(geom as Polygon2 <double>));
         }
         else if (geom is PolygonSet2 <double> )
         {
             return(ToPGis(geom as PolygonSet2 <double>));
         }
         else if (geom is PolygonBag2 <double> )
         {
             return(ToPGis(geom as PolygonBag2 <double>));
         }
         else if (geom is Ring2 <double> )
         {
             return(ToPGis(geom as Ring2 <double>));
         }
         else if (geom is LineChain2 <double> )
         {
             return(ToPGis(geom as LineChain2 <double>));
         }
         else if (geom is LineChainSet2 <double> )
         {
             return(ToPGis(geom as LineChainSet2 <double>));
         }
         else if (geom is LineChainBag2 <double> )
         {
             return(ToPGis(geom as LineChainBag2 <double>));
         }
         else if (geom is Polyline2 <double> )
         {
             return(ToPGis(geom as Polyline2 <double>));
         }
         else if (geom is PolylineSet2 <double> )
         {
             return(ToPGis(geom as PolylineSet2 <double>));
         }
         else if (geom is PolylineBag2 <double> )
         {
             return(ToPGis(geom as PolylineBag2 <double>));
         }
         else if (geom is PointSet2 <double> )
         {
             return(ToPGis(geom as PointSet2 <double>));
         }
         else if (geom is PointBag2 <double> )
         {
             return(ToPGis(geom as PointBag2 <double>));
         }
     }
     return(null);
 }
예제 #13
0
파일: Utils3D.cs 프로젝트: secondii/Yutai
        public static IMultiPatch Cylinder(IPoint ipoint_0, double double_0, double double_1, double double_2, double double_3, double double_4, bool bool_0, bool bool_1)
        {
            double              num                = 36.0;
            object              value              = Missing.Value;
            double              num2               = (double_2 - double_1) / num;
            double              num3               = double_2 - double_1;
            IMultiPatch         multiPatch         = new MultiPatch() as IMultiPatch;
            IGeometryCollection geometryCollection = multiPatch as IGeometryCollection;
            IPointCollection    pointCollection    = new TriangleStrip();
            IVector3D           vector3D           = new Vector3D() as IVector3D;
            IEncode3DProperties encode3DProperties = new GeometryEnvironment() as IEncode3DProperties;

            for (double num4 = double_2; num4 <= double_1; num4 += -num2)
            {
                double num5 = Utils3D.DegreesToRadians(num4);
                vector3D.PolarSet(-num5, 0.0, double_0);
                IPoint point = new Point();
                point.X = ipoint_0.X + vector3D.XComponent;
                point.Y = ipoint_0.Y + vector3D.YComponent;
                point.Z = double_3;
                double num6 = (num4 - double_1) / num3;
                if (bool_0)
                {
                    num6 = 1.0 + num6 * -1.0;
                }
                if (num6 <= 0.0)
                {
                    num6 = 0.001;
                }
                else if (num6 >= 1.0)
                {
                    num6 = 0.999;
                }
                double textureT;
                if (bool_1)
                {
                    textureT = 0.0;
                }
                else
                {
                    textureT = 1.0;
                }
                double m = 0.0;
                encode3DProperties.PackTexture2D(num6, textureT, out m);
                point.M = m;
                pointCollection.AddPoint(point, ref value, ref value);
                IClone clone  = point as IClone;
                IPoint point2 = clone.Clone() as IPoint;
                point2.Z = double_4;
                if (bool_1)
                {
                    textureT = 1.0;
                }
                else
                {
                    textureT = 0.0;
                }
                m = 0.0;
                encode3DProperties.PackTexture2D(num6, textureT, out m);
                point2.M = m;
                pointCollection.AddPoint(point2, ref value, ref value);
            }
            IGeometry2 inGeometry = pointCollection as IGeometry2;

            geometryCollection.AddGeometry(inGeometry, ref value, ref value);
            IZAware iZAware = multiPatch as IZAware;

            iZAware.ZAware = true;
            IMAware iMAware = multiPatch as IMAware;

            iMAware.MAware = true;
            return(multiPatch);
        }
예제 #14
0
        public static void Handle(UserSecurityContext user, string method, HttpContext context, CancellationToken cancel)
        {
            if (context.Request.Method == "POST")
            {
                if (method.Equals("all", StringComparison.OrdinalIgnoreCase))
                {
                    Get(user, context, cancel);
                    return;
                }
                else if (method.Equals("find", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        JToken token = JsonUtils.GetDataPayload(context.Request);
                        if (token != null)
                        {
                            if (token["name"] != null)
                            {
                                GetName(token["name"].ToString(), user, context, cancel);
                                return;
                            }
                            else if (token["orgid"] != null)
                            {
                                GetByOwner(JsonUtils.ToId(token["orgid"]), user, context, cancel);
                                return;
                            }
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("in", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        HashSet <CompoundIdentity> ids = JsonUtils.ToIds(JsonUtils.GetDataPayload(context.Request));
                        if (ids != null)
                        {
                            GetIds(ids, user, context, cancel);
                            return;
                        }
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("parent", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        JToken                     token    = JsonUtils.GetDataPayload(context.Request);
                        CompoundIdentity           id       = JsonUtils.ToId(token["id"]);
                        CompoundIdentity           parentid = JsonUtils.ToId(token["parentid"]);
                        HashSet <CompoundIdentity> cids     = JsonUtils.ToIds(token["childid"]);
                        bool del = token["remove"] != null ? (bool)token["remove"] : false;

                        if (parentid != null && cids != null)
                        {
                            if (del)
                            {
                                Remove(parentid, cids, user, context, cancel);
                                return;
                            }
                            else
                            {
                                Add(parentid, cids, user, context, cancel);
                                return;
                            }
                        }
                        else if (id != null)
                        {
                            GetParent(id, user, context, cancel);
                            return;
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("children", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        CompoundIdentity cid = JsonUtils.ToId(JsonUtils.GetDataPayload(context.Request));
                        if (cid != null)
                        {
                            GetChildren(cid, user, context, cancel);
                            return;
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("create", StringComparison.OrdinalIgnoreCase))
                {
                    CompoundIdentity owning_orgid = null;
                    string           name         = null;
                    string           desc         = null;
                    SiteProviderBase provider     = null;
                    JToken           token        = null;

                    try
                    {
                        //payload and provider
                        token    = JsonUtils.GetDataPayload(context.Request);
                        provider = SiteManager.Instance.GetSiteProvider(user);
                        if (provider != null && token != null)
                        {
                            //required inputs
                            name         = token["name"].ToString();
                            owning_orgid = JsonUtils.ToId(token["orgid"]);
                            if (owning_orgid != null && !string.IsNullOrEmpty(name))
                            {
                                desc = token["desc"] != null ? token["desc"].ToString() : null;

                                HashSet <CompoundIdentity> pids = JsonUtils.ToIds(token["parentid"]); //could be >= 1, or null

                                //create
                                Site site = null;
                                site = provider.Create(owning_orgid, name, desc);
                                if (site != null)
                                {
                                    //add parents if necessary
                                    bool result = true;
                                    if (pids != null)
                                    {
                                        foreach (CompoundIdentity p in pids)
                                        {
                                            result &= provider.AddParent(site.Identity, p);  //parents are not returned with newly created site.  This was just a convenience for REST /create
                                        }
                                    }
                                    if (result == true)
                                    {
                                        JObject jsite = Jsonifier.ToJson(site);
                                        if (jsite != null)
                                        {
                                            RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, jsite.ToString()));
                                        }
                                        else
                                        {
                                            RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                                        }
                                        return;
                                    }
                                }
                            }
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("delete", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        JToken t = JsonUtils.GetDataPayload(context.Request);
                        HashSet <CompoundIdentity> cids     = JsonUtils.ToIds(t);
                        SiteProviderBase           provider = SiteManager.Instance.GetSiteProvider(user);
                        if (provider != null && cids != null)
                        {
                            bool result = true;
                            foreach (CompoundIdentity cid in cids)
                            {
                                result &= provider.Delete(cid);
                            }

                            if (result == true)
                            {
                                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok));
                            }
                            else
                            {
                                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                            }
                            return;
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
                else if (method.Equals("update", StringComparison.OrdinalIgnoreCase))
                {
                    CompoundIdentity           cid     = null;
                    CompoundIdentity           org_cid = null;
                    HashSet <CompoundIdentity> pids    = null;
                    string name  = null;
                    string desc  = null;
                    bool   dirty = false;

                    try
                    {
                        //provider and token
                        JToken           token    = JsonUtils.GetDataPayload(context.Request);
                        SiteProviderBase provider = SiteManager.Instance.GetSiteProvider(user);
                        if (provider != null && token != null)
                        {
                            //GUID must be provided
                            cid = JsonUtils.ToId(token["id"]);

                            //fetch stored object
                            Site site = provider.Get(cid);
                            if (site != null)
                            {
                                //## REQUIRED ##

                                //name
                                if (token.SelectToken("name") != null)
                                {
                                    name = token["name"].ToString();
                                    if (!string.IsNullOrEmpty(name))
                                    {
                                        site.Name = name;
                                        dirty     = true;
                                    }
                                    else
                                    {
                                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //name is required and not nullable
                                        return;
                                    }
                                }

                                //owning org
                                if (token.SelectToken("orgid") != null)
                                {
                                    org_cid = JsonUtils.ToId(token["orgid"]);
                                    if (org_cid != null)
                                    {
                                        site.OwningOrganizationIdentity = org_cid;
                                        dirty = true;
                                    }
                                    else
                                    {
                                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //owning org is required and not nullable
                                        return;
                                    }
                                }

                                //## OPTIONALS ##

                                //description
                                if (token.SelectToken("desc") != null)
                                {
                                    desc             = (token["desc"] != null) ? token["desc"].ToString() : null;
                                    site.Description = desc;
                                    dirty            = true;
                                }

                                //geom
                                if (token.SelectToken("geom") != null)
                                {
                                    IGeometry2 <double> geom = Jsonifier.IsNullOrEmpty(token["geom"]) ? null : GeoJsonUtils.ParseGeometry(token["geom"].ToString());
                                    site.Location = geom;
                                    dirty         = true;
                                }

                                //altgeom
                                if (token.SelectToken("altgeom") != null)
                                {
                                    Point2 <double> altgeom = Jsonifier.IsNullOrEmpty(token["altgeom"]) ? null : GeoJsonUtils.ParseGeometry(token["altgeom"].ToString()) as Point2 <double>;
                                    site.LocationMark = altgeom;
                                    dirty             = true;
                                }

                                //update
                                bool result = true;
                                if (dirty)
                                {
                                    //update
                                    result &= provider.Update(site);
                                    if (result == false)
                                    {
                                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                                        return;
                                    }
                                }

                                //site hierarchy
                                if (token.SelectToken("parentid") != null)
                                {
                                    pids = JsonUtils.ToIds(token["parentid"]);                      //new parents
                                    IEnumerable <Site> existing_parents = provider.GetParents(cid); //existing parents

                                    if (pids == null)                                               //clear all parent assignments
                                    {
                                        foreach (Site p in existing_parents)
                                        {
                                            result &= provider.RemoveParent(cid, p.Identity);
                                        }
                                    }
                                    else
                                    {
                                        //remove unlisted, keep listed
                                        foreach (Site p in existing_parents)
                                        {
                                            if (pids.Contains(p.Identity) == false)
                                            {
                                                result &= provider.RemoveParent(cid, p.Identity);
                                            }
                                        }

                                        //add new
                                        foreach (CompoundIdentity new_pid in pids)
                                        {
                                            bool contains = false;
                                            foreach (Site p in existing_parents)
                                            {
                                                if (p.Identity == new_pid)
                                                {
                                                    contains = true;
                                                }
                                                break;
                                            }
                                            if (contains == false)
                                            {
                                                result &= provider.AddParent(cid, new_pid);
                                            }
                                        }
                                    }
                                }

                                if (result == true)
                                {
                                    //return ok - no values were modified
                                    RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok));
                                    return;
                                }
                            }
                        }

                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                        return;
                    }
                }
            }

            context.Response.StatusCode = HttpStatusCodes.Status400BadRequest;
        }
예제 #15
0
        public static IGeometry2 <double> ExtractGeometry(JObject o)
        {
            IGeometry2 <double> geometry1 = null;

            o = GeoJsonUtils.ExtractGeoJson(o);
            if (o != null)
            {
                JObject jobject = (JObject)null;
                string  str1    = (string)null;
                KeyValuePair <string, JObject> crs = GeoJsonUtils.GetCrs(o);
                if (crs.Key != null)
                {
                    jobject = crs.Value;
                    str1    = crs.Key;
                }
                JToken jtoken1 = o["type"];
                if (jtoken1 != null && jtoken1.Type == JTokenType.String)
                {
                    string str2 = jtoken1.ToString();
                    if (!string.IsNullOrEmpty(str2))
                    {
                        string str3 = str2;
                        if (str3 == "Feature")
                        {
                            JToken jtoken2 = o["geometry"];
                            if (jtoken2 == null || jtoken2.Type != JTokenType.Object)
                            {
                                return(null);
                            }
                            JObject o1 = jtoken2 as JObject;
                            if (jobject != null)
                            {
                                o1["crs"] = (JToken)jobject;
                            }
                            return(GeoJsonUtils.ExtractGeometry(o1));
                        }
                        if (str3 == "FeatureCollection")
                        {
                            JToken jtoken2 = o["features"];
                            if (jtoken2 != null && jtoken2.Type == JTokenType.Array)
                            {
                                JArray jarray = (JArray)jtoken2;
                                List <IGeometry2 <double> > list = new List <IGeometry2 <double> >();
                                foreach (JToken jtoken3 in jarray)
                                {
                                    if (jtoken3 != null && jtoken3.Type == JTokenType.Object)
                                    {
                                        JObject o1 = jtoken2 as JObject;
                                        if (jobject != null && o1["crs"] == null)
                                        {
                                            o1["crs"] = (JToken)jobject;
                                        }
                                        IGeometry2 <double> geometry2 = GeoJsonUtils.ExtractGeometry(o1);
                                        if (geometry2 == null)
                                        {
                                            return(null);
                                        }
                                        list.Add(geometry2);
                                    }
                                }
                                //return (Geometry)(Geometry.DefaultFactory.CreateGeometryCollection((IGeometry[])list.ToArray()) as GeometryCollection);
                                return(null); //right now we can't handle mixed geometry types
                            }
                        }
                        else if (str3 == "GeometryCollection")
                        {
                            JToken jtoken2 = o["geometries"];
                            if (jtoken2 != null && jtoken2.Type == JTokenType.Array)
                            {
                                JArray jarray = (JArray)jtoken2;
                                List <IGeometry2 <double> > list = new List <IGeometry2 <double> >();
                                foreach (JToken jtoken3 in jarray)
                                {
                                    if (jtoken3 != null && jtoken3.Type == JTokenType.Object)
                                    {
                                        JObject o1 = jtoken2 as JObject;
                                        if (jobject != null && o1["crs"] == null)
                                        {
                                            o1["crs"] = (JToken)jobject;
                                        }
                                        IGeometry2 <double> geometry2 = GeoJsonUtils.ExtractGeometry(o1);
                                        if (geometry2 == null)
                                        {
                                            return(null);
                                        }
                                        list.Add(geometry2);
                                    }
                                }
                                //return (Geometry)(Geometry.DefaultFactory.CreateGeometryCollection((IGeometry[])list.ToArray()) as GeometryCollection);
                                return(null); //right now we can't handle mixed geometry types
                            }
                        }
                        else
                        {
                            JToken jtoken2 = o["coordinates"];
                            if (jtoken2 != null && jtoken2.Type == JTokenType.Array)
                            {
                                JArray arr = jtoken2 as JArray;
                                if (arr != null)
                                {
                                    if ("Point" == str2)
                                    {
                                        geometry1 = GeometryUtils.BuildPoint(GeoJsonUtils.FetchCoordinates(arr, PositionType.Point));
                                    }
                                    else if ("MultiPoint" == str2)
                                    {
                                        geometry1 = GeometryUtils.BuildMultiPoint(GeoJsonUtils.FetchCoordinates(arr, PositionType.MultiPoint));
                                    }
                                    else if ("LineString" == str2)
                                    {
                                        geometry1 = GeometryUtils.BuildLineString(GeoJsonUtils.FetchCoordinates(arr, PositionType.LineString));
                                    }
                                    else if ("MultiLineString" == str2)
                                    {
                                        geometry1 = GeometryUtils.BuildMultiLineString(GeoJsonUtils.FetchCoordinates(arr, PositionType.MultiLineString));
                                    }
                                    else if ("Polygon" == str2)
                                    {
                                        geometry1 = GeometryUtils.BuildPolygon(GeoJsonUtils.FetchCoordinates(arr, PositionType.Polygon));
                                    }
                                    else if ("MultiPolygon" == str2)
                                    {
                                        geometry1 = GeometryUtils.BuildMultiPolygon(GeoJsonUtils.FetchCoordinates(arr, PositionType.MultiPolygon));
                                    }
                                    //if (geometry1 != null && jobject != null)
                                    //    geometry1.UserData = (object)str1;  //TODO - deal with the JTable issue
                                    return(geometry1);
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }