public static string GetGeoJsonFromShapeZip(IUserContext userContext, string fileName, Stream fileStream) { //Get save path var zipFilePath = InitFileSave(userContext, fileName, false); //Save file to disk using (var zipFile = File.Create(zipFilePath)) { fileStream.CopyTo(zipFile); zipFile.Close(); fileStream.Close(); fileStream.Dispose(); } //Get temp directory for user var tempDirectory = GetTempDirectory(userContext); //Make sure temp direcory dosn't exists ForceDeleteDirectory(tempDirectory); //Extract files to temp dir ZipFile.ExtractToDirectory(zipFilePath, tempDirectory); //Delete zip file var zipfile = new FileInfo(zipFilePath); zipfile.Delete(); //Get shape files from extracted files var shapeFiles = Directory.GetFiles(tempDirectory, "*.shp"); if (shapeFiles.Length == 0) { throw new ImportGisFileException("No shapefile found in .zip-file. Please check that there are no subdirectories in the zip file you use. The data files must be located in the root."); } if (shapeFiles.Length != 1) { throw new ImportGisFileException("It should only be one shapefile in the .zip-file"); } var shapeFile = shapeFiles[0]; string jsonString = null; using (var jsonStreamReader = new StreamReader(ShapeConverter.ConvertToGeoJsonStream(shapeFile))) { jsonString = jsonStreamReader.ReadToEnd(); jsonStreamReader.Close(); } //Clean Up, make sure temp direcory dosn't exists ForceDeleteDirectory(tempDirectory); return(jsonString); }
public void CanReadShapeFromListOfDecimal() { var list = new List <decimal> { 5.7m, 9.2m }; var shapeConvert = new ShapeConverter(); string result; Assert.True(shapeConvert.TryConvert(list, out result)); Assert.Equal("POINT (5.7 9.2)", result); }
void Landed(GameObject landedShape) { Shape shape = landedShape.GetComponent <Shape>(); // Convert the landedShape to blocks and add to the gird ShapeConverter.ConvertShapesToBlocksOnGrid(shape, _blockGrid); if (gameOver) { return; } StartCoroutine(CheckLines()); }
static SpatialField() { GeometryServiceProvider.Instance = new NtsGeometryServices(); GeoContext = new NtsSpatialContext(true); ShapeConverter = new ShapeConverter(); }
public void Init(ConfigCreator ccreator, LevelConfig lcfg, int levelindex, int maxindex) { creator = ccreator; cfg = lcfg; myindex = levelindex; this.maxindex = maxindex; creator.LevelAdded += new ConfigCreator.LevelAddHandler(LevelInserted); creator.LevelDeleted += LevelDeleted; UpdateTitle(); LineStrokeSlider.value = (float)LineStroke.FloatToInt(lcfg.lineStroke); LineStrokeSlider.onValueChanged.AddListener(f => SetStroke(f)); ShapeDropdown.options.Clear(); foreach (string option in ShapeConverter.GetShapeStringArray()) { ShapeDropdown.options.Add(new Dropdown.OptionData(option)); } ShapeDropdown.onValueChanged.AddListener(i => UpdateShape(i)); int index = 0; foreach (var option in ShapeDropdown.options) { if (option.text == ShapeConverter.shapeToString(lcfg.shape)) { // Strange workaround ShapeDropdown.value = index + 1; ShapeDropdown.value = index; break; } index++; } LineColorDropdown.options.Clear(); foreach (PastelColor option in PastelColorFactory.ColorList) { LineColorDropdown.options.Add(new Dropdown.OptionData(option.Name)); } LineColorDropdown.onValueChanged.AddListener(i => UpdateLineColor(i)); index = 0; foreach (var option in LineColorDropdown.options) { if (option.text == lcfg.brushColor.Name) { // Strange workaround LineColorDropdown.value = index + 1; LineColorDropdown.value = index; break; } index++; } ShapeColorDropdown.options.Clear(); //ShapeColorDropdown.options.Add(new Dropdown.OptionData("Losowy")); foreach (PastelColor option in PastelColorFactory.ColorList) { ShapeColorDropdown.options.Add(new Dropdown.OptionData(option.Name)); } ShapeColorDropdown.onValueChanged.AddListener(i => UpdateShapeColor(i)); index = 0; foreach (var option in ShapeColorDropdown.options) { if (option.text == lcfg.shapeColor.Name) { // Strange workaround ShapeColorDropdown.value = index + 1; ShapeColorDropdown.value = index; break; } index++; } StayingPoint = transform.localPosition; AddNextLevelBtn.onClick.AddListener(() => creator.SendMessage("AddLevel", myindex + 1)); AddPrevLevelBtn.onClick.AddListener(() => creator.SendMessage("AddLevel", myindex)); updateBtns(); }
private void UpdateShape(int i) { cfg.shape = ShapeConverter.stringToShape(ShapeDropdown.options[i].text); }