Beispiel #1
0
        public List <VectorRecordPointer> GetVRPTs(DataField field)
        {
            List <VectorRecordPointer> result = new List <VectorRecordPointer>();

            if (field.Tag == "VRPT")
            {
                int currentIndex = 0;
                while (field.Bytes[currentIndex] != DataField.FieldTerminator && currentIndex < field.Bytes.Length)
                {
                    VectorRecordPointer vectorRecordPointer = new VectorRecordPointer();
                    var  rcnm          = field.Bytes[currentIndex++];;
                    uint unsignedValue = 0;
                    for (int i = 0; i < 4; i++)
                    {
                        UInt32 tempVal = field.Bytes[currentIndex++];
                        for (int j = 0; j < i; j++)
                        {
                            tempVal = tempVal << 8;
                        }
                        unsignedValue += tempVal;
                    }
                    var rcid = unsignedValue;
                    vectorRecordPointer.Name        = new VectorName(rcnm, rcid);
                    vectorRecordPointer.Orientation = (Orientation)field.Bytes[currentIndex++];
                    vectorRecordPointer.Topology    = (TopologyIndicator)field.Bytes[currentIndex++];
                    vectorRecordPointer.Usage       = (Usage)field.Bytes[currentIndex++];
                    vectorRecordPointer.Mask        = (Masking)field.Bytes[currentIndex++];
                    result.Add(vectorRecordPointer);
                }
            }
            return(result);
        }
Beispiel #2
0
        public Vector(NAMEkey _namekey, DataRecord _VectorRecord)
        {
            namekey      = _namekey;
            VectorRecord = _VectorRecord;
            var vrpt = _VectorRecord.Fields.GetFieldByTag("VRPT");

            if (vrpt != null)
            {
                enhVectorPtrs = new VectorRecordPointer(vrpt.subFields);
            }
            var attv = _VectorRecord.Fields.GetFieldByTag("ATTV");

            if (attv != null)
            {
                Attributes = GetAttributes(attv);
            }
        }
Beispiel #3
0
        // Link to Vector Objects
        public List <VectorRecordPointer> GetFSPTs(DataField field)
        {
            List <VectorRecordPointer> result = new List <VectorRecordPointer>();

            if (field.Tag == "FSPT")
            {
                int currentIndex = 0;
                while (field.Bytes[currentIndex] != DataField.FieldTerminator && currentIndex < field.Bytes.Length)
                {
                    VectorRecordPointer spatialLink = new VectorRecordPointer();
                    var  rcnm = field.Bytes[currentIndex++];
                    uint rcid;
                    currentIndex            = GetUint4Bytes(field, currentIndex, out rcid);
                    spatialLink.Name        = new VectorName(rcnm, rcid);
                    spatialLink.Orientation = (Orientation)field.Bytes[currentIndex++];
                    spatialLink.Usage       = (Usage)field.Bytes[currentIndex++];
                    spatialLink.Mask        = (Masking)field.Bytes[currentIndex++];
                    result.Add(spatialLink);
                }
            }
            return(result);
        }
Beispiel #4
0
        public Feature(NAMEkey _namekey, DataRecord _FeatureRecord)
        {
            namekey       = _namekey;
            FeatureRecord = _FeatureRecord;
            var fspt = _FeatureRecord.Fields.GetFieldByTag("FSPT");

            if (fspt != null)
            {
                enhVectorPtrs = new VectorRecordPointer(fspt.subFields);
            }
            var ffpt = _FeatureRecord.Fields.GetFieldByTag("FFPT");

            if (ffpt != null)
            {
                enhFeaturePtrs = new FeatureObjectPointer(ffpt.subFields);
            }
            // FRID : Feature Record Identifier
            var frid = _FeatureRecord.Fields.GetFieldByTag("FRID");

            if (frid != null)
            {
                Primitive  = (GeometricPrimitive)frid.subFields.GetUInt32(0, "PRIM");
                Group      = frid.subFields.GetUInt32(0, "GRUP");
                ObjectCode = (S57Obj)frid.subFields.GetUInt32(0, "OBJL");
            }
            // FOID : Feature Object Identifier
            var foid = _FeatureRecord.Fields.GetFieldByTag("FOID");

            if (foid != null)
            {
                subFieldRow = foid.subFields.Values[0];
                tagLookup   = foid.subFields.TagIndex;
                agen        = subFieldRow.GetUInt32(tagLookup["AGEN"]);
                fidn        = subFieldRow.GetUInt32(tagLookup["FIDN"]);
                fids        = subFieldRow.GetUInt32(tagLookup["FIDS"]);
                lnam        = new LongName(agen, fidn, fids);
            }
            // ATTF : Attributes
            var attr = _FeatureRecord.Fields.GetFieldByTag("ATTF");

            if (attr != null)
            {
                Attributes = Vector.GetAttributes(attr);
            }
            // NATF : National attributes NATF.
            var natf = _FeatureRecord.Fields.GetFieldByTag("NATF");

            if (natf != null)
            {
                var natfAttr = Vector.GetAttributes(natf);
                if (Attributes != null)
                {
                    foreach (var entry in natfAttr)
                    {
                        Attributes.Add(entry.Key, entry.Value);
                    }
                }
                else
                {
                    Attributes = natfAttr;
                }
            }
        }
Beispiel #5
0
        public Geometry GetGeometry()
        {
            int count;

            switch (Primitive)
            {
            case GeometricPrimitive.Point:
            {
                if (VectorPtrs[0] == null || VectorPtrs[0].Vector == null)
                {
                    return(null);
                }
                return(VectorPtrs[0].Vector.Geometry);
            }

            case GeometricPrimitive.Line:
            {
                //initialize StartNode Pointer for later check how to build geometry
                VectorRecordPointer StartNode = new VectorRecordPointer();
                //initialize Contour to accumulate lines
                Line Contour = new Line();
                for (int i = 0; i < VectorPtrs.Count; i++)
                {
                    var vectorPtr = VectorPtrs[i];
                    //first, check if vector exist, and if it is supposed to be visible
                    //(to improve: masked points should still be added for correct topology, just not rendered later)
                    if (vectorPtr.Vector == null || vectorPtr.Mask == Masking.Mask)
                    {
                        break;
                    }

                    //next, check if edge needs to be reversed for the intended usage
                    //Do this on a copy to not mess up original record wich might be used elsewhere
                    var edge = new List <Point>((vectorPtr.Vector.Geometry as Line).points);
                    if (vectorPtr.Orientation == Orientation.Reverse)
                    {
                        edge.Reverse();
                        //note: Reversing is not reversing the VectorRecordPointers, see S57 Spec 3.1 section 3.20 (i.e. index [0] is now end node instead of start node)
                        //therefore assign private StartNode pointer for some later checks
                        StartNode = vectorPtr.Vector.VectorRecordPointers[1];
                    }
                    else
                    {
                        StartNode = vectorPtr.Vector.VectorRecordPointers[0];
                    }

                    //now check if Contour has already accumulated points, if not just add current edge
                    count = Contour.points.Count;
                    if (count > 0)
                    {
                        //now check if existing contour should be extended
                        if (Contour.points[count - 1] == StartNode.Vector.Geometry as Point)
                        {
                            Contour.points.AddRange(edge.GetRange(1, edge.Count - 1));
                        }
                    }
                    else
                    {
                        //add current edge points to new contour
                        Contour.points.AddRange(edge);
                    }
                }
                //done, finish up and return
                return(Contour);
            }

            case GeometricPrimitive.Area:
            {
                //initialize PolygonSet to accumulate 1 exterior and (if available) repeated interior boundaries
                PolygonSet ContourSet = new PolygonSet();
                //initialize StartNode Pointer for check how to build geometry
                VectorRecordPointer StartNode = new VectorRecordPointer();
                //initialize Contour to accumulate boundaries
                Area Contour = new Area();
                for (int i = 0; i < VectorPtrs.Count; i++)
                {
                    var vectorPtr = VectorPtrs[i];
                    //first, check if vector exist, and if it is supposed to be visible
                    //(to improve: masked points should still be added for correct topology, just not rendered later)
                    if (vectorPtr.Vector == null || vectorPtr.Mask == Masking.Mask)
                    {
                        break;
                    }

                    //next, check if edge needs to be reversed for the intended usage
                    //Do this on a copy to not mess up original record wich might be used elsewhere
                    var edge = new List <Point>((vectorPtr.Vector.Geometry as Line).points);
                    if (vectorPtr.Orientation == Orientation.Reverse)
                    {
                        edge.Reverse();
                        //note: Reversing is not reversing the VectorRecordPointers, see S57 Spec 3.1 section 3.20 (i.e. index [0] is now end node instead of start node)
                        //therefore assign private StartNode pointer for some later checks
                        StartNode = vectorPtr.Vector.VectorRecordPointers[1];
                    }
                    else
                    {
                        StartNode = vectorPtr.Vector.VectorRecordPointers[0];
                    }

                    //now check if Contour has already accumulated points, if not just add current edge
                    count = Contour.points.Count;
                    if (count > 0)
                    {
                        //now check if existing contour should be extended, or if a new one for the next interior boundery should be started
                        if (Contour.points[count - 1] == StartNode.Vector.Geometry as Point)
                        {
                            Contour.points.AddRange(edge.GetRange(1, edge.Count - 1));
                        }
                        else
                        {
                            //done, add current polygon boundery to ContourSet
                            //verify that polygone is closed last point in list equals first
                            if (Contour.points[count - 1] == Contour.points[0])
                            {
                                ContourSet.Areas.Add(Contour);
                            }
                            else
                            {
                                //Debug.WriteLine("Panic: current polygon is not complete, and current egde is not extending it");
                            }
                            //initialize new contour to accumulate next boundery, add current edge to it
                            Contour = new Area();
                            Contour.points.AddRange(edge);
                        }
                    }
                    else
                    {
                        //add current edge points to new contour
                        Contour.points.AddRange(edge);
                    }
                }
                //done, finish up and return
                ContourSet.Areas.Add(Contour);
                return(ContourSet);
            }
            }
            return(null);
        }