Exemplo n.º 1
0
 private IEnumerator LoadJSON(string txt)
 {
     //Debug.Log("Enter LoadJSON");
     Collection = GeoJSONObject.Deserialize(txt);
     yield return(loadedJSON = true);
     //Debug.Log("Exit LoadJSON");
 }
Exemplo n.º 2
0
    /// <summary>
    /// Called when the "Import" button is clicked
    /// </summary>
    private void OnWizardCreate()
    {
        GameObject parentGameObject = new GameObject();

        parentGameObject.name = this.ParentName;

        try
        {
            FeatureCollection features = GeoJSONObject.Deserialize(this.GeoJSONSource.text);

            MapBounds bounds = features.bbox;
            bounds.ProjectToWebMercator();
            bounds.SetScale(this.HorizontalScale);

            this.UpdateCameraParameters(bounds.Center.ToVector3(), this.HorizontalScale, this.VerticalScale);

            foreach (FeatureObject ftr in features.features)
            {
                MapFeature feature = new MapFeature(ftr.properties[this.ObjectIDFieldName]);

                List <Vertex> vertices = ftr.geometry.AllPositions().ConvertAll((v) => new Vertex(v.latitude, v.longitude, 0.0));

                feature.SetAttributes(ftr.properties);
                feature.SetGeometry(EnumGeometryType.Polygon, vertices);

                if (feature.Geometry.IsEmpty)
                {
                    continue;
                }

                feature.Geometry.ProjectToWebMercator();
                feature.Geometry.SetScale(this.HorizontalScale);

                Vector3 cityOrigin = feature.Geometry.GetCentroid();

                GameObject go = feature.ToGameObject();
                go.transform.position = cityOrigin - bounds.Center.ToVector3();
                go.transform.parent   = parentGameObject.transform;

                Material material = new Material(Shader.Find("Standard"));
                material.color = Color.gray;// UnityEngine.Random.ColorHSV();
                go.GetComponent <Renderer>().material = material;

                if (this.Extrude)
                {
                    float height = feature.Attributes.Get <float>(this.ExtrudeField);

                    if (height > 0)
                    {
                        height = height * this.ExtrudeFactor;
                        MeshExtrusion.Extrude(go, height, this.InvertFaces);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Debug.Log(ex);
        }
    }
Exemplo n.º 3
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;
        }