public static void Run()
        {
            //ExStart: ConvertGeoJsonToTopoJsonWithQuantization
            // convert GeoJSON to TopoJSON with quantization - transforming doubles to integers
            // to reduce file size.

            string SampleGeoJsonPath = RunExamples.GetDataDir() + "sample.geojson";
            var    outputFilePath    = RunExamples.GetDataDir() + "convertedSampleWithQuantization_out.topojson";

            var options = new ConversionOptions
            {
                DestinationDriverOptions = new TopoJsonOptions
                {
                    // There are two ways to set quantization parameters - with Transform property or
                    // with quantization number. Here we specify quantization number.
                    // Quantization number specifies number of expressible values per dimension in a result
                    // coordinates.
                    QuantizationNumber = 100_000,

                    // Alternatively, 'Transform' property can be set (but not simultaneously with quantization number).
                    // Refer to TopoJSON specification for more details on transform object and quantization.
                    //
                    // Transform = new TopoJsonTransform(
                    //     xTranslate: 0,
                    //     yTranslate: 0,
                    //     xScale: 0.0001000010000100001,
                    //     yScale: 0.0001000010000100001),
                }
            };

            VectorLayer.Convert(SampleGeoJsonPath, Drivers.GeoJson, outputFilePath, Drivers.TopoJson, options);
            //ExEnd: ConvertGeoJsonToTopoJsonWithQuantization
        }
 public static void ConvertFeaturesFromFileGdbToGeoJson()
 {
     File.Delete(dataDir + "ThreeLayers_out.json");
     //ExStart: ConvertFeaturesFromFileGdbToGeoJson
     //This will convert FileGDB dataset with three layers into single layered GeoJSON.
     VectorLayer.Convert(dataDir + "ThreeLayers.gdb", Drivers.FileGdb, dataDir + "ThreeLayers_out.json", Drivers.GeoJson);
     //ExEnd: ConvertFeaturesFromFileGdbToGeoJson
 }
        public static void Run()
        {
            //ExStart: ConvertGeoJsonToTopoJson
            string sampleGeoJsonPath = RunExamples.GetDataDir() + "sample.geojson";
            var    outputFilePath    = RunExamples.GetDataDir() + "convertedSample_out.topojson";

            VectorLayer.Convert(sampleGeoJsonPath, Drivers.GeoJson, outputFilePath, Drivers.TopoJson);
            //ExEnd: ConvertGeoJsonToTopoJson
        }
예제 #4
0
        public static void Run()
        {
            string dataDir       = RunExamples.GetDataDir();
            string shapefilePath = dataDir + "InputShapeFile.shp";
            string jsonPath      = dataDir + "output_out.json";

            //ExStart: ConvertShapeFileToGeoJSON
            VectorLayer.Convert(shapefilePath, Drivers.Shapefile, jsonPath, Drivers.GeoJson);
            //ExEnd: ConvertShapeFileToGeoJSON
        }
예제 #5
0
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir();
            //ExStart: ConvertGeoJSONToShapeFileWithAttributeAdjustment
            ConversionOptions options = new ConversionOptions();

            options.AttributesConverter = new AttributesConverterExample();

            VectorLayer.Convert(dataDir + "input.json", Drivers.GeoJson, dataDir + "ConvertGeoJSONToShapeFileWithAttributeAdjustment_out.shp", Drivers.Shapefile, options);
            //ExEnd: ConvertGeoJSONToShapeFileWithAttributeAdjustment
        }
        public static void Run()
        {
            //ExStart: ConvertGeoJsonToTopoJsonAndSpecifyObjectName
            string sampleGeoJsonPath = RunExamples.GetDataDir() + "sample.geojson";
            var    outputFilePath    = RunExamples.GetDataDir() + "convertedSampleWithObjectName_out.topojson";

            var options = new ConversionOptions
            {
                DestinationDriverOptions = new TopoJsonOptions
                {
                    // specify the name of the object where features should be written
                    DefaultObjectName = "name_of_the_object",
                }
            };

            VectorLayer.Convert(sampleGeoJsonPath, Drivers.GeoJson, outputFilePath, Drivers.TopoJson, options);
            //ExEnd: ConvertGeoJsonToTopoJsonAndSpecifyObjectName
        }
예제 #7
0
        public static void Run()
        {
            //ExStart: ConvertGeoJsonToTopoJsonWithGroupingIntoObjects
            string sampleGeoJsonPath = RunExamples.GetDataDir() + "sample.geojson";
            var    outputFilePath    = RunExamples.GetDataDir() + "convertedSampleWithGrouping_out.topojson";

            var options = new ConversionOptions
            {
                DestinationDriverOptions = new TopoJsonOptions
                {
                    // we set the attribute in GeoJSON layer by which we are going to group into objects
                    ObjectNameAttribute = "group",
                    // if value of "group" is unknown for some feature it should be placed into object with name "unnamed".
                    DefaultObjectName = "unnamed",
                }
            };

            VectorLayer.Convert(sampleGeoJsonPath, Drivers.GeoJson, outputFilePath, Drivers.TopoJson, options);
            //ExEnd: ConvertGeoJsonToTopoJsonWithGroupingIntoObjects
        }
예제 #8
0
        ///<Summary>
        /// ConvertGisFormat method to convert gis format to different format
        ///</Summary>
        public Response ConvertGisFormat(string fileName, string folderName, string outputType)
        {
            if (outputType.StartsWith("kml") || outputType.StartsWith("json") || outputType.StartsWith("geojson") || outputType.StartsWith("shx"))
            {
                Driver sourceDriver      = GetDriverType(fileName);
                Driver destinationDriver = GetDriverType(outputType);

                if (sourceDriver != null && destinationDriver != null)
                {
                    return(ProcessTask(fileName, folderName, "." + outputType, false, false, delegate(string inFilePath, string outPath, string zipOutFolder)
                    {
                        VectorLayer.Convert(inFilePath, (FileDriver)sourceDriver, outPath, (FileDriver)destinationDriver);
                    }));
                }
            }

            return(new Response
            {
                FileName = null,
                Status = "Output type not found",
                StatusCode = 500
            });
        }
예제 #9
0
        public static void Main(string[] args)
        {
            // This program manipulates the GIS data on the Azure Blob storage.
            // It uses an inheritor of "Aspose.GIS.AbstractPath". If you need to implement your own inheritor of
            // "Aspose.GIS.AbstractPath" to support some external file storage, refer to "AzurePath" class.
            // This program:
            // - crates a GeoJSON layer on the Azure Blob storage;
            // - reads a Shapefile from the Azure Blob storage and prints its geometries;
            // - converts the Shapefile located on the Azure Blob Storage to the KML file located on the same storage.

            // First - we need to get the blob container
            var blobContainer = GetBlobContainer("azureintegrationcontainer");

            // -- Create a GeoJSON Layer in the Azure Blob Storage --
            // Create an instance of 'AzurePath'. 'AzurePath' is an inheritor of 'AbstratPath'
            // and we can use it to make Aspose.GIS work with Azure Blob storage.
            // See the AzurePath class for detailed description on how it works and how you can implement
            // your own inheritor of 'AbstractPath'.
            var geoJsonAzurePath = new AzurePath(blobContainer, "directory/file.json");

            // Delete a geojson file if it exists.
            geoJsonAzurePath.Delete();
            // Create the layer.
            using (var layer = VectorLayer.Create(geoJsonAzurePath, Drivers.GeoJson))
            {
                layer.Attributes.Add(new FeatureAttribute("id", AttributeDataType.Integer));
                var feature = layer.ConstructFeature();
                feature.SetValue("id", 1);
                feature.Geometry = new Point(1, 2);
                layer.Add(feature);

                feature = layer.ConstructFeature();
                feature.SetValue("id", 2);
                feature.Geometry = new Point(3, 4);
                layer.Add(feature);
            }
            var geoJsonText = blobContainer.GetBlockBlobReference("directory/file.json").DownloadText();

            Console.WriteLine("Created GeoJSON:");
            Console.WriteLine(geoJsonText);
            // --

            // There is no way to create a Shapefile via AzurePath, since Shapefile requires write streams to support
            // seeking. We upload the Shapefile from the local file system.
            blobContainer.GetBlockBlobReference("shapefile/point.shp").UploadFromFile("shapefile/point.shp");
            blobContainer.GetBlockBlobReference("shapefile/point.shx").UploadFromFile("shapefile/point.shx");
            blobContainer.GetBlockBlobReference("shapefile/point.dbf").UploadFromFile("shapefile/point.dbf");

            Console.WriteLine("Shapefile Geometries:");
            // -- Read the Shapefile From the Azure Blob Storage --
            var shapefileAzurePath = new AzurePath(blobContainer, "shapefile/point.shp");

            using (var layer = VectorLayer.Open(shapefileAzurePath, Drivers.Shapefile))
            {
                foreach (var feature in layer)
                {
                    Console.WriteLine(feature.Geometry.AsText());
                }
            }
            // --
            Console.WriteLine();

            // -- Convert the Shapefile on the Azure Blob Storage to the KML on the Same Storage --
            var kmlAzurePath = new AzurePath(blobContainer, "kml.kml");

            // Delete destination if it already exists
            kmlAzurePath.Delete();
            VectorLayer.Convert(shapefileAzurePath, Drivers.Shapefile, kmlAzurePath, Drivers.Kml);
            // --

            var kmlText = blobContainer.GetBlockBlobReference("kml.kml").DownloadText();

            Console.WriteLine("Converted KML:");
            Console.WriteLine(kmlText);
        }