public static IRecordSet GetRecordSetFromFeatureClass(IFeatureClass featureClass, List <int> fids, List <string> fields, uint epsg)
 {
     if (null != featureClass)
     {
         IQueryFilter2 queryFilter = new QueryFilterClass();
         queryFilter.AddField(featureClass.OIDFieldName);
         queryFilter.AddField(featureClass.ShapeFieldName);
         if (null != fields)
         {
             foreach (var fld in fields)
             {
                 queryFilter.AddField(fld);
             }
         }
         ISpatialReference srs = GetSpatialReference(epsg);
         if (null != srs)
         {
             queryFilter.set_OutputSpatialReference(featureClass.ShapeFieldName, srs);
         }
         queryFilter.WhereClause = featureClass.OIDFieldName + " IN (" + string.Join(",", System.Array.ConvertAll <int, string>(fids.ToArray(), s => s.ToString(System.Globalization.CultureInfo.InvariantCulture))) + ")";
         return(ConvertToRecordset(featureClass, queryFilter));
     }
     return(null);
 }
示例#2
0
        private byte[] ExportGeoJsonHandler(NameValueCollection boundVariables,
                                            JsonObject operationInput,
                                            string outputFormat,
                                            string requestProperties,
                                            out string responseProperties)
        {
            responseProperties = null;
            bool   applyQuery = true;
            string retval     = "";
            string whereClause;
            bool   found = operationInput.TryGetString("query", out whereClause);

            if (!found || string.IsNullOrEmpty(whereClause))
            {
                //then no definition query
                applyQuery = false;
            }

            long?layerOrdinal;

            found = operationInput.TryGetAsLong("layer", out layerOrdinal); //.TryGetString("layer", out parm2Value);
            if (!found)
            {
                throw new ArgumentNullException("layer");
            }

            string s = "";

            ESRI.ArcGIS.Carto.IMapServer           mapServer        = (ESRI.ArcGIS.Carto.IMapServer)serverObjectHelper.ServerObject;
            ESRI.ArcGIS.Carto.IMapServerDataAccess mapServerObjects = (ESRI.ArcGIS.Carto.IMapServerDataAccess)mapServer;
            var lyr = mapServerObjects.GetDataSource(mapServer.DefaultMapName, Convert.ToInt32(layerOrdinal));

            if (lyr is IFeatureClass)
            {
                IFeatureClass fclass = (IFeatureClass)lyr;
                retval = "{\"shape\": \"" + fclass.ShapeFieldName + "\"}";
                IQueryFilter filter = new QueryFilterClass();
                filter.set_OutputSpatialReference(fclass.ShapeFieldName, getWGS84());
                if (applyQuery)
                {
                    filter.WhereClause = whereClause;
                }
                IFeatureCursor curs = fclass.Search(filter, false);
                //apply extension methods here
                try
                {
                    s = curs.ToGeoJson();
                    Marshal.ReleaseComObject(curs);
                }
                catch (Exception ex)
                {
                    s = ex.GetBaseException().ToString(); //.StackTrace;
                }
                retval = s;
            }
            else
            {
                throw new Exception("Layer " + layerOrdinal.ToString() + " is not a feature layer.");
            }
            return(Encoding.UTF8.GetBytes(retval));
        }
示例#3
0
        private byte[] ExportCsvHandler(NameValueCollection boundVariables,
                                          JsonObject operationInput,
                                              string outputFormat,
                                              string requestProperties,
                                          out string responseProperties)
        {
            string retval = "";
            StringBuilder sb = new StringBuilder();
            string s = "";
            bool applyQuery = true;
            bool? applyHeader = true;
            //bool? applyGeoms = true;
            bool addHeader = false;
            //bool addGeoms = false;
            responseProperties = "{\"Content-Type\" : \"text/csv\"}";

            string whereClause = "";
            bool found = operationInput.TryGetString("query", out whereClause);
            if (!found || string.IsNullOrEmpty(whereClause))
            {
                //then no definition query
                applyQuery = false;
            }

            long? layerOrdinal;
            found = operationInput.TryGetAsLong("layer", out layerOrdinal); //.TryGetString("layer", out parm2Value);
            if (!found)
            {
                throw new ArgumentNullException("layer");
            }

            bool useHeader = operationInput.TryGetAsBoolean("headers", out applyHeader);
            if (useHeader)
            {
                if ((bool)applyHeader)
                {
                    addHeader = true;
                }
            }

            //bool useGeoms = operationInput.TryGetAsBoolean("addgeoms", out applyGeoms);
            //if (useGeoms)
            //{
            //    if ((bool)applyGeoms)
            //    {
            //        addGeoms = true;
            //    }
            //}

            ESRI.ArcGIS.Carto.IMapServer mapServer = (ESRI.ArcGIS.Carto.IMapServer)serverObjectHelper.ServerObject;
            ESRI.ArcGIS.Carto.IMapServerDataAccess mapServerObjects = (ESRI.ArcGIS.Carto.IMapServerDataAccess)mapServer;
            var lyr = mapServerObjects.GetDataSource(mapServer.DefaultMapName, Convert.ToInt32(layerOrdinal));
            if (lyr is IFeatureClass)
            {
                IFeatureClass fclass = (IFeatureClass)lyr;
                IQueryFilter filter = new QueryFilterClass();
                filter.set_OutputSpatialReference(fclass.ShapeFieldName, getWGS84());
                if (applyQuery)
                {
                    filter.WhereClause = whereClause;
                }
                IFeatureCursor curs = fclass.Search(filter, false);
                try
                {
                    //();
                    s = curs.ToCSV(addHeader);
                    Marshal.ReleaseComObject(curs);

                }
                catch (Exception ex)
                {
                    s = ex.GetBaseException().ToString(); //.StackTrace;
                }
                retval = s;
                sb.Append(retval);
            }
            else
            {
                throw new Exception("Layer " + layerOrdinal.ToString() + " is not a feature layer.");
            }

            return Encoding.UTF8.GetBytes(sb.ToString());
        }
示例#4
0
        private byte[] ExportCsvHandler(NameValueCollection boundVariables,
                                        JsonObject operationInput,
                                        string outputFormat,
                                        string requestProperties,
                                        out string responseProperties)
        {
            string        retval      = "";
            StringBuilder sb          = new StringBuilder();
            string        s           = "";
            bool          applyQuery  = true;
            bool?         applyHeader = true;
            //bool? applyGeoms = true;
            bool addHeader = false;

            //bool addGeoms = false;
            responseProperties = "{\"Content-Type\" : \"text/csv\"}";

            string whereClause = "";
            bool   found       = operationInput.TryGetString("query", out whereClause);

            if (!found || string.IsNullOrEmpty(whereClause))
            {
                //then no definition query
                applyQuery = false;
            }

            long?layerOrdinal;

            found = operationInput.TryGetAsLong("layer", out layerOrdinal); //.TryGetString("layer", out parm2Value);
            if (!found)
            {
                throw new ArgumentNullException("layer");
            }

            bool useHeader = operationInput.TryGetAsBoolean("headers", out applyHeader);

            if (useHeader)
            {
                if ((bool)applyHeader)
                {
                    addHeader = true;
                }
            }

            //bool useGeoms = operationInput.TryGetAsBoolean("addgeoms", out applyGeoms);
            //if (useGeoms)
            //{
            //    if ((bool)applyGeoms)
            //    {
            //        addGeoms = true;
            //    }
            //}

            ESRI.ArcGIS.Carto.IMapServer           mapServer        = (ESRI.ArcGIS.Carto.IMapServer)serverObjectHelper.ServerObject;
            ESRI.ArcGIS.Carto.IMapServerDataAccess mapServerObjects = (ESRI.ArcGIS.Carto.IMapServerDataAccess)mapServer;
            var lyr = mapServerObjects.GetDataSource(mapServer.DefaultMapName, Convert.ToInt32(layerOrdinal));

            if (lyr is IFeatureClass)
            {
                IFeatureClass fclass = (IFeatureClass)lyr;
                IQueryFilter  filter = new QueryFilterClass();
                filter.set_OutputSpatialReference(fclass.ShapeFieldName, getWGS84());
                if (applyQuery)
                {
                    filter.WhereClause = whereClause;
                }
                IFeatureCursor curs = fclass.Search(filter, false);
                try
                {
                    //();
                    s = curs.ToCSV(addHeader);
                    Marshal.ReleaseComObject(curs);
                }
                catch (Exception ex)
                {
                    s = ex.GetBaseException().ToString(); //.StackTrace;
                }
                retval = s;
                sb.Append(retval);
            }
            else
            {
                throw new Exception("Layer " + layerOrdinal.ToString() + " is not a feature layer.");
            }

            return(Encoding.UTF8.GetBytes(sb.ToString()));
        }