예제 #1
0
 static void WriteFields(List <GISField> fields, BinaryWriter bw)
 {
     for (int fieldindex = 0; fieldindex < fields.Count; fieldindex++)
     {
         GISField field = fields[fieldindex];
         bw.Write(TypeToInt(field.datatype));
         WriteString(field.name, bw);
     }
 }
예제 #2
0
        static List <GISFeature> ReadFeatures(BinaryReader br, SHAPETYPE ShapeType, List <GISField> Fields, int FeatureCount)
        {
            List <GISFeature> Features = new List <GISFeature>();

            for (int featureindex = 0; featureindex < FeatureCount; featureindex++)
            {
                GISFeature feature = new GISFeature(null, null);
                if (ShapeType == SHAPETYPE.POINT)
                {
                    GISVertex _location = ReadVertex(br);
                    feature.spatialpart = new GISPoint(_location);
                }
                else if (ShapeType == SHAPETYPE.LINE)
                {
                    List <GISVertex> vs = new List <GISVertex>();
                    int vcount          = br.ReadInt32();
                    for (int vc = 0; vc < vcount; vc++)
                    {
                        vs.Add(ReadVertex(br));
                    }
                    feature.spatialpart = new GISLine(vs);
                }
                else if (ShapeType == SHAPETYPE.POLYGON)
                {
                    List <GISVertex> vs = new List <GISVertex>();
                    int vcount          = br.ReadInt32();
                    for (int vc = 0; vc < vcount; vc++)
                    {
                        vs.Add(ReadVertex(br));
                    }
                    feature.spatialpart = new GISPolygon(vs);
                }
                GISAttribute ga = new GISAttribute();
                for (int fieldindex = 0; fieldindex < Fields.Count; fieldindex++)
                {
                    GISField field = Fields[fieldindex];
                    if (field.datatype == typeof(int))
                    {
                        ga.AddValue(br.ReadInt32());
                    }
                    else if (field.datatype == typeof(double))
                    {
                        ga.AddValue(br.ReadDouble());
                    }
                    else if (field.datatype == typeof(string))
                    {
                        ga.AddValue(ReadString(br));
                    }
                }
                feature.attributepart = ga;
                Features.Add(feature);
            }
            return(Features);
        }
예제 #3
0
        static void WriteFeatures(GISLayer layer, BinaryWriter bw)
        {
            for (int featureindex = 0; featureindex < layer.Features.Count; featureindex++)
            {
                GISFeature feature = layer.Features[featureindex];
                if (layer.ShapeType == SHAPETYPE.POINT)
                {
                    WriteVertex(((GISPoint)feature.spatialpart).Location, bw);
                }
                else if (layer.ShapeType == SHAPETYPE.LINE)
                {
                    GISLine line = (GISLine)(feature.spatialpart);
                    bw.Write(line.Vertexes.Count);
                    for (int vc = 0; vc < line.Vertexes.Count; vc++)
                    {
                        WriteVertex(line.Vertexes[vc], bw);
                    }
                }
                else if (layer.ShapeType == SHAPETYPE.POLYGON)
                {
                    GISPolygon polygon = (GISPolygon)(feature.spatialpart);
                    bw.Write(polygon.Vertexes.Count);
                    for (int vc = 0; vc < polygon.Vertexes.Count; vc++)
                    {
                        WriteVertex(polygon.Vertexes[vc], bw);
                    }
                }

                for (int fieldindex = 0; fieldindex < layer.Fields.Count; fieldindex++)
                {
                    GISField field = layer.Fields[fieldindex];
                    int      tint  = TypeToInt(field.datatype);
                    if (tint == 1)
                    {
                        bw.Write((int)(feature.getAttributeValue(fieldindex)));
                    }
                    else if (tint == 2)
                    {
                        bw.Write(Convert.ToDouble(feature.getAttributeValue(fieldindex)));
                    }
                    else if (tint == 3)
                    {
                        WriteString(feature.getAttributeValue(fieldindex).ToString(), bw);
                    }
                }
            }
        }