示例#1
0
        public virtual void Load()
        {
            if (Data == null)
            {
                return;
            }

            string[] lines = Data.text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            // Run checks on the data to ensure it will work
            if (!CheckData(Data.name, lines))
            {
                return;
            }

            // Load header
            string[] header = lines[0].Split(split);

            // Create a list of arrays of data
            originalData = new List <string[]>();
            for (int i = 0; i < header.Length; i++)
            {
                originalData.Add(new string[lines.Length - 1]);
            }

            for (int i = 1; i < lines.Length; i++)
            {
                string[] values = lines[i].Split(split);

                for (int j = 0; j < values.Length; j++)
                {
                    originalData[j][i - 1] = values[j];
                }
            }

            // Create the attribute data objects
            attributes = new List <DataAttribute>();
            for (int i = 0; i < header.Length; i++)
            {
                IATKDataType dataType = DataTypesExtension.InferFromString(originalData[i][0]);
                attributes.Add(new DataAttribute(header[i], dataType, originalData[i]));
            }

            DataCount = lines.Length - 1;
        }
示例#2
0
        public override void Load()
        {
            if (Data == null)
            {
                return;
            }

            // Load the geoJSON file
            FeatureCollection collection = GeoJSONObject.Deserialize(Data.text);

            // Create a list of lists that we will be populating with our fortified shape data
            List <List <string> > geoData = new List <List <string> >();

            for (int i = 0; i < 5; i++)
            {
                geoData.Add(new List <string>());
            }

            // Create another dictionary of lists that will contain the properties that are encoded within the geoJSON file
            Dictionary <string, List <string> > propertyData = new Dictionary <string, List <string> >();

            foreach (string property in collection.features[0].properties.Keys)
            {
                propertyData[property] = new List <string>();
            }

            for (int i = 0; i < collection.features.Count; i++)
            {
                FeatureObject feature = collection.features[i];

                int order = 0;

                if (feature.geometry.type == "Polygon")
                {
                    PolygonGeometryObject geometry = (PolygonGeometryObject)feature.geometry;

                    for (int j = 0; j < geometry.coordinates.Count; j++)
                    {
                        List <PositionObject> positionObjects = geometry.coordinates[j];

                        for (int k = 0; k < positionObjects.Count - 1; k++)     // Ignore last coordinate
                        {
                            PositionObject point = positionObjects[k];
                            geoData[0].Add(point.longitude.ToString());
                            geoData[1].Add(point.latitude.ToString());
                            geoData[2].Add(order.ToString());
                            geoData[3].Add(i.ToString());
                            geoData[4].Add(j.ToString());

                            foreach (var property in feature.properties)
                            {
                                propertyData[property.Key].Add(property.Value);
                            }

                            order++;
                        }
                    }
                }
                else if (feature.geometry.type == "MultiPolygon")
                {
                    MultiPolygonGeometryObject geometry = (MultiPolygonGeometryObject)feature.geometry;

                    for (int j = 0; j < geometry.coordinates.Count; j++)
                    {
                        List <List <PositionObject> > polygon = geometry.coordinates[j];

                        for (int k = 0; k < polygon.Count; k++)
                        {
                            List <PositionObject> positionObjects = polygon[k];

                            for (int l = 0; l < positionObjects.Count - 1; l++)     // Ignore last coordinate
                            {
                                PositionObject point = positionObjects[l];
                                geoData[0].Add(point.longitude.ToString());
                                geoData[1].Add(point.latitude.ToString());
                                geoData[2].Add(order.ToString());
                                geoData[3].Add(i.ToString());
                                geoData[4].Add(j.ToString());

                                foreach (var property in feature.properties)
                                {
                                    propertyData[property.Key].Add(property.Value);
                                }

                                order++;
                            }
                        }
                    }
                }
            }

            // Populate data structures
            originalData = new List <string[]>();
            attributes   = new List <DataAttribute>();

            foreach (var list in geoData)
            {
                originalData.Add(list.ToArray());
            }

            attributes.Add(new DataAttribute("Longitude", IATKDataType.Numeric, originalData[0].ToArray()));
            attributes.Add(new DataAttribute("Latitude", IATKDataType.Numeric, originalData[1].ToArray()));
            attributes.Add(new DataAttribute("Order", IATKDataType.Numeric, originalData[2].ToArray()));
            attributes.Add(new DataAttribute("Group", IATKDataType.Factor, originalData[3].ToArray()));
            attributes.Add(new DataAttribute("Piece", IATKDataType.Factor, originalData[4].ToArray()));


            foreach (var property in propertyData)
            {
                string[]     array    = property.Value.ToArray();
                IATKDataType dataType = DataTypesExtension.InferFromString(array[0]);
                originalData.Add(array);
                attributes.Add(new DataAttribute(property.Key, dataType, array));
            }

            DataCount = attributes[0].Length;
        }