private static Geometry GetGeometryFromBuffer(byte[] geomBuffer, SpatialReference sr)
        {
            var geomType = GetGeometryType(geomBuffer);

            switch (geomType)
            {
            case GeometryType.Point:
            {
                int    offset = 4;
                double x      = DoubleWithNaN(BitConverter.ToDouble(geomBuffer, offset));
                offset += 8;
                double y = DoubleWithNaN(BitConverter.ToDouble(geomBuffer, offset));

                var mp = MapPointBuilderEx.FromEsriShape(geomBuffer, sr);
                //System.Diagnostics.Debug.WriteLine($@"x: {x} = {mp.X} y: {y} = {mp.Y}");
                return(mp);
            }

            case GeometryType.Polyline:
            {
                var line = PolylineBuilderEx.FromEsriShape(geomBuffer, sr);
                return(line);
            }

            case GeometryType.Polygon:
            {
                var poly = PolygonBuilderEx.FromEsriShape(geomBuffer, sr);
                return(poly);
            }
            }
            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Custom interface specific to the way the sample is implemented.
        /// </summary>
        public PluginRow FindRow(long oid, IEnumerable <string> columnFilter, SpatialReference srout)
        {
            Geometry shape = null;

            List <object> values = new List <object>();
            var           row    = _table.Rows.Find(oid);
            //The order of the columns in the returned rows ~must~ match
            //GetFields. If a column is filtered out, an empty placeholder must
            //still be provided even though the actual value is skipped
            var columnNames = this.GetFields().Select(col => col.Name.ToUpper()).ToList();

            foreach (var colName in columnNames)
            {
                if (columnFilter.Contains(colName))
                {
                    //special handling for shape
                    if (colName == "SHAPE")
                    {
                        var buffer = row["SHAPE"] as Byte[];
                        shape = MapPointBuilderEx.FromEsriShape(buffer, _sr);
                        if (srout != null)
                        {
                            if (!srout.Equals(_sr))
                            {
                                shape = GeometryEngine.Instance.Project(shape, srout);
                            }
                        }
                        values.Add(shape);
                    }
                    else
                    {
                        values.Add(row[colName]);
                    }
                }
                else
                {
                    values.Add(System.DBNull.Value);//place holder
                }
            }
            return(new PluginRow()
            {
                Values = values
            });
        }