Esempio n. 1
0
        public static void WriteFeature(StringBuilder sb, IGeoJsonFeatureStyle style, IFeatureDataRecord feature)
        {
            IGeometry g = style.PreProcessGeometries
                              ? style.GeometryPreProcessor(feature.Geometry)
                              : feature.Geometry;

            sb.Append("{");
            sb.Append("\"type\":\"Feature\",");
            if (feature.HasOid)
            {
                sb.Append(JsonUtility.FormatJsonAttribute("id", feature.GetOid()));
                sb.Append(",");
            }

            sb.Append("\"properties\":");
            WriteFeatureAttributes(sb, style, feature);
            sb.Append(",");

            if (style.IncludeBBox)
            {
                sb.Append("\"bbox\":");
                WriteExtents(sb, g.Extents, style.CoordinateNumberFormatString);
                sb.Append(",");
            }

            /* Ideally this should be higher up e.g at the layer level but we dont currently
             * have anywhere where we can group features by layer.
             * It still complies with the spec but will be considerably more verbose */

            if (g.SpatialReference != null || !string.IsNullOrEmpty(g.Srid))
            {
                sb.Append("\"crs\":");
                WriteNamedCrs(sb,
                              g.SpatialReference != null
                                  ? g.SpatialReference.Name
                                  : "EPSG:" + SridMap.DefaultInstance.Process(g.SpatialReference, 0));
                sb.Append(",");
            }

            sb.Append("\"geometry\":");
            WriteGeometry(sb, g, style.CoordinateNumberFormatString);

            sb.Append("}");
            sb.AppendLine();
        }
Esempio n. 2
0
        public FeatureDataRow <TTarget> ConvertRow(IFeatureDataRecord source)
        {
            if (typeof(TSource) == typeof(TTarget) && source is FeatureDataRow)
            {
                return(source as FeatureDataRow <TTarget>);
            }
            TTarget oid = _conversionDelegate((TSource)source.GetOid());
            FeatureDataRow <TTarget> row = _target.NewRow(oid);

            object[] vals = new object[source.FieldCount];
            vals[_oidColumnIndex] = oid;
            source.GetValues(vals);
            row.ItemArray = vals;
            //row.Geometry = source.Geometry.IsValid ? source.Geometry : source.Geometry.Buffer(0.0);
            row.Geometry = source.Geometry;

            return(row);
        }
        public static void WriteFeature(StringBuilder sb, IGeoJsonFeatureStyle style, IFeatureDataRecord feature)
        {
            IGeometry g = style.PreProcessGeometries
                              ? style.GeometryPreProcessor(feature.Geometry)
                              : feature.Geometry;
            sb.Append("{");
            sb.Append("\"type\":\"Feature\",");
            if (feature.HasOid)
            {
                sb.Append(JsonUtility.FormatJsonAttribute("id", feature.GetOid()));
                sb.Append(",");
            }

            sb.Append("\"properties\":");
            WriteFeatureAttributes(sb, style, feature);
            sb.Append(",");

            if (style.IncludeBBox)
            {
                sb.Append("\"bbox\":");
                WriteExtents(sb, g.Extents, style.CoordinateNumberFormatString);
                sb.Append(",");
            }

            /* Ideally this should be higher up e.g at the layer level but we dont currently 
             * have anywhere where we can group features by layer. 
             * It still complies with the spec but will be considerably more verbose */

            if (g.SpatialReference != null || !string.IsNullOrEmpty(g.Srid))
            {
                sb.Append("\"crs\":");
                WriteNamedCrs(sb,
                              g.SpatialReference != null
                                  ? g.SpatialReference.Name
                                  : "EPSG:" + SridMap.DefaultInstance.Process(g.SpatialReference, 0));
                sb.Append(",");
            }

            sb.Append("\"geometry\":");
            WriteGeometry(sb, g, style.CoordinateNumberFormatString);

            sb.Append("}");
            sb.AppendLine();
        }
Esempio n. 4
0
        protected override IEnumerable <GeoJsonRenderObject> DoRenderFeature(IFeatureDataRecord feature,
                                                                             GeoJsonLabelStyle style,
                                                                             RenderState state, ILayer layer)
        {
            FeatureDataRow fdr = (FeatureDataRow)feature;

            string text = fdr.Evaluate(style.LabelExpression);


            StringBuilder sb = new StringBuilder();

            sb.Append("{");
            sb.Append(JsonUtility.FormatJsonAttribute("type", "Label"));
            sb.Append(",");
            sb.Append(JsonUtility.FormatJsonAttribute("id", feature.GetOid()));
            sb.Append(",");
            sb.Append(JsonUtility.FormatJsonAttribute("text", text));
            sb.Append(",");


            IGeometry geom;

            if (style.IncludeGeometryData)
            {
                geom = style.PreProcessGeometries
                           ? style.GeometryPreProcessor(feature.Geometry)
                           : feature.Geometry;
            }
            else
            {
                geom = feature.Geometry.Centroid;
            }

            sb.Append("\"shape\":");
            GeoJsonFeatureWriter.WriteGeometry(sb, geom, style.CoordinateNumberFormatString);
            sb.Append("}");


            yield return(new GeoJsonRenderObject(sb.ToString()));
        }
        internal void MergeFeature(IFeatureDataRecord record)
        {
            if (record == null) throw new ArgumentNullException("record");

            bool checkForTarget = false;

            if ((SchemaMergeAction & SchemaMergeAction.Add) != SchemaMergeAction.None)
            {
                // HACK: Parsing and setting the schema should be less clunky here.
                //      We probably need to just do the schema merge ourselves without having 
                //      to rely on System.Data.Merger
                FeatureDataTable schemaModel = createModelFromFeature(record);
                MergeSchema(schemaModel);
                checkForTarget = _target.Rows.Count > 0 && (_target.PrimaryKey.Length > 0);
            }

            FeatureDataRow targetFeature = null;

            if (checkForTarget && record.HasOid)
            {
                targetFeature = _target.Find(record.GetOid());
            }

            mergeFeature(_target, record, targetFeature, PreserveChanges);
        }
 public object GetOid()
 {
     return(record.GetOid());
 }
Esempio n. 7
0
        //private SchemaMap _schemaMap = new SchemaMap();

        //private delegate Object Converter(Object input);

        //private class SchemaMap
        //{
        //    private readonly List<SchemaMapColumnMatch> _columnMatches = new List<SchemaMapColumnMatch>();
        //    private readonly List<SchemaMapKeyMatch> _keyMatches = new List<SchemaMapKeyMatch>();

        //    public void AddColumnMatch(DataColumn src, DataColumn dst)
        //    {
        //        AddColumnMatch(src, dst, null);
        //    }

        //    public void AddColumnMatch(DataColumn src, DataColumn dst, Converter converter)
        //    {
        //        SchemaMapColumnMatch match = new SchemaMapColumnMatch(src, dst, converter);
        //        _columnMatches.Add(match);
        //    }

        //    public void AddKeyMatch(DataColumn src, DataColumn dst)
        //    {
        //        SchemaMapKeyMatch match = new SchemaMapKeyMatch(src, dst);
        //        _keyMatches.Add(match);
        //    }

        //    public SchemaMapColumnMatch GetColumnMatch(Int32 index)
        //    {
        //        return _columnMatches[index];
        //    }

        //    public SchemaMapKeyMatch GetKeyMatch(Int32 index)
        //    {
        //        return _keyMatches[index];
        //    }
        //}

        //private class SchemaMapKeyMatch
        //{
        //    private readonly DataColumn _srcColumn;
        //    private readonly DataColumn _dstColumn;

        //    public SchemaMapKeyMatch(DataColumn src, DataColumn dst)
        //    {
        //        _srcColumn = src;
        //        _dstColumn = dst;
        //    }

        //    public DataColumn Destination
        //    {
        //        get { return _dstColumn; }
        //    }

        //    public DataColumn Source
        //    {
        //        get { return _srcColumn; }
        //    }
        //}

        //private class SchemaMapColumnMatch
        //{
        //    private readonly DataColumn _srcColumn;
        //    private readonly DataColumn _dstColumn;
        //    private readonly Converter _converter;

        //    public SchemaMapColumnMatch(DataColumn src, DataColumn dst, Converter converter)
        //    {
        //        _srcColumn = src;
        //        _converter = converter;
        //        _dstColumn = dst;
        //    }

        //    public Converter Converter
        //    {
        //        get { return _converter; }
        //    }

        //    public DataColumn Destination
        //    {
        //        get { return _dstColumn; }
        //    }

        //    public DataColumn Source
        //    {
        //        get { return _srcColumn; }
        //    }
        //}

        //private static DataTable mergeSchema(DataTable source, DataSet targetDataSet, DataTable target, SchemaMergeAction mergeAction, Boolean preserveChanges)
        //{
        //    Boolean ignoreCase = ((Int32)(mergeAction & SchemaMergeAction.CaseInsensitive) != 0);
        //    DataTable targetTable = null;

        //    if (targetDataSet != null)
        //    {
        //        if (tablesContain(targetDataSet, ignoreCase, source.TableName))
        //        {
        //            targetTable = targetDataSet.Namespace != source.Namespace
        //                            ? targetDataSet.Tables[source.TableName]
        //                            : targetDataSet.Tables[source.TableName, source.Namespace];
        //        }
        //    }
        //    else
        //    {
        //        targetTable = target;
        //    }

        //    if (targetTable == null)    // This will be true when the targetDataSet doesn't have a table by the same name
        //    {
        //        throw new NotImplementedException("DataSet merges not yet implemented.");
        //    }
        //    else
        //    {
        //        if (mergeAction == SchemaMergeAction.None)
        //        {
        //            mergeExtendedProperties(source.ExtendedProperties, targetTable.ExtendedProperties, mergeAction, preserveChanges);
        //            return targetTable;
        //        }

        //        Int32 initialTargetCount = targetTable.Columns.Count;
        //        Boolean matchIfConvertible = (Int32)(mergeAction & SchemaMergeAction.MatchIfConvertible) != 0;
        //        Boolean includeKey = (Int32)(mergeAction & SchemaMergeAction.Key) != 0;
        //        Boolean add = (Int32)(mergeAction & SchemaMergeAction.AddAll) != 0;
        //        Boolean replace = (Int32)(mergeAction & SchemaMergeAction.Replace) != 0;

        //        for (int i = 0; i < source.Columns.Count; i++)
        //        {
        //            DataColumn src = source.Columns[i];
        //            DataColumn dest = columnsContain(targetTable, source, src.ColumnName, src.DataType, ignoreCase, matchIfConvertible, includeKey)
        //                                            ? targetTable.Columns[src.ColumnName]
        //                                            : null;
        //            if (dest == null)
        //            {
        //                // rematch using type coersion to System.Object to ensure match
        //                dest = columnsContain(targetTable, src.ColumnName, typeof(Object), ignoreCase, true, includeKey)
        //                                            ? targetTable.Columns[src.ColumnName]
        //                                            : null;

        //                if (dest != null && replace)
        //                {
        //                    // Find common type to convert to (widen for numeric and character data, cast up for objects)
        //                    // Add new column with found type
        //                    // Copy existing dest data to new column from old column
        //                    // Remove original destination column
        //                    throw new NotImplementedException("Schema replacement not yet implemented");
        //                }
        //            }

        //            if (dest == null)
        //            {
        //                if (add)
        //                {
        //                    dest = _cloneDataColumn(src);
        //                    targetTable.Columns.Add(dest);
        //                }
        //                else if (!isKey(source, src) || (includeKey && isKey(source, src)))
        //                {
        //                    // TODO: raise merge failed event
        //                    throw new DataException("Merge failed, can't match column: " + src.ColumnName);
        //                }
        //            }
        //            else
        //            {
        //                if (matchIfConvertible)
        //                {
        //                    throw new NotImplementedException("Schema matching on convertible types not yet implemented");
        //                }
        //                else if (dest.DataType != src.DataType ||
        //                        ((dest.DataType == typeof(DateTime)) &&
        //                        (dest.DateTimeMode != src.DateTimeMode) &&
        //                        ((dest.DateTimeMode & src.DateTimeMode) != DataSetDateTime.Unspecified)))
        //                {
        //                    throw new DataException("Merge failed, data type mismatch: " + src.ColumnName);
        //                }

        //                mergeExtendedProperties(src.ExtendedProperties, dest.ExtendedProperties, mergeAction, preserveChanges);
        //            }

        //            // Set expressions 
        //            if (targetDataSet != null)
        //            {
        //                throw new NotImplementedException("DataSet merges not yet implemented.");
        //                //for (int i = initialTargetCount; i < targetTable.Columns.Count; i++)
        //                //{
        //                //    targetTable.Columns[i].Expression = source.Columns[targetTable.Columns[i].ColumnName].Expression;
        //                //}
        //            }

        //            // 
        //            DataColumn[] targetKey = targetTable.PrimaryKey;
        //            DataColumn[] sourceKey = source.PrimaryKey;

        //            if (targetKey.Length != sourceKey.Length)
        //            {
        //                // special case when the target table does not have the PrimaryKey

        //                if (targetKey.Length == 0)
        //                {
        //                    DataColumn[] key = new DataColumn[sourceKey.Length];

        //                    for (Int32 i = 0; i < sourceKey.Length; i++)
        //                    {
        //                        key[i] = targetTable.Columns[sourceKey[i].ColumnName];
        //                    }

        //                    targetTable.PrimaryKey = key;
        //                }
        //                else if (sourceKey.Length != 0)
        //                {
        //                    targetDataSet.RaiseMergeFailed(targetTable, Res.GetString(Res.DataMerge_PrimaryKeyMismatch), missingSchemaAction);
        //                }
        //            }
        //            else
        //            {
        //                for (int i = 0; i < targetKey.Length; i++)
        //                {
        //                    if (String.Compare(targetKey[i].ColumnName, sourceKey[i].ColumnName, false, targetTable.Locale) != 0)
        //                    {
        //                        targetDataSet.RaiseMergeFailed(source,
        //                            Res.GetString(Res.DataMerge_PrimaryKeyColumnsMismatch, targetKey[i].ColumnName, sourceKey[i].ColumnName),
        //                            missingSchemaAction
        //                    );
        //                    }
        //                }
        //            }
        //        }

        //        mergeExtendedProperties(source.ExtendedProperties, targetTable.ExtendedProperties, mergeAction, preserveChanges);
        //    }

        //    return targetTable;
        //}

        //private static Boolean isKey(DataTable table, DataColumn column)
        //{
        //    return Array.Exists(table.PrimaryKey, delegate(DataColumn find) { return ReferenceEquals(find, column); });
        //}

        //private static Boolean tablesContain(DataSet targetDataSet, Boolean ignoreCase, String name)
        //{
        //    StringComparer comparer = StringComparer.Create(targetDataSet.Locale ?? CultureInfo.CurrentCulture, ignoreCase);

        //    foreach (DataTable table in targetDataSet.Tables)
        //    {
        //        if (comparer.Compare(table.TableName, name) == 0)
        //        {
        //            return true;
        //        }
        //    }

        //    return false;
        //}

        //private static Boolean columnsContain(DataTable table, String columnName, Type columnType, Boolean ignoreCase, Boolean matchIfConvertible, Boolean includeKey)
        //{
        //    StringComparer comparer = StringComparer.Create(table.Locale ?? CultureInfo.CurrentCulture, ignoreCase);

        //    foreach (DataColumn column in table.Columns)
        //    {
        //        if (comparer.Compare(column.ColumnName, columnName) == 0)
        //        {
        //            return true;
        //        }
        //    }

        //    return false;
        //}

        #endregion

        internal void MergeFeature(IFeatureDataRecord record, IGeometryFactory factory)
        {
            if (record == null)
            {
                throw new ArgumentNullException("record");
            }

            Boolean checkForTarget = _targetDataTable.Rows.Count > 0 &&
                                     (_targetDataTable.PrimaryKey.Length > 0);

            mergeSchemaIfNeeded(record, factory);

            FeatureDataRow targetFeature = null;

            if (checkForTarget && record.HasOid)
            {
                targetFeature = _targetDataTable.Find(record.GetOid());
            }

            mergeFeature(_targetDataTable, record, targetFeature, _columnMap, _transform, _geoFactory, PreserveChanges);
        }