Closed livewirewarrior closed 3 years ago
@evermanwa
@evermanwa did you ever resolve this?
@livewirewarrior - Check my answer for the solution I came up with.
@evermanwa for prms.Add("json,json) is your json variable just a string that you read in?
Yes, all I had to do was read in the geojson as a string and it worked for me. Are you receiving any errors?
On Tue, Apr 11, 2017 at 3:08 PM, livewirewarrior notifications@github.com wrote:
@evermanwa https://github.com/evermanwa for prms.Add("json,json) is your json variable just a string that you read in?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/wavded/ogre/issues/64#issuecomment-293385178, or mute the thread https://github.com/notifications/unsubscribe-auth/AQvOZg71lNTvLlOs4g1Ur2AbkvJZnTupks5ru92ygaJpZM4M6iIC .
@evermanwa how did you save the data that you should have received from OGRE? All I see is that you have the return method. I assume you saved it to a file?>
I will show you how I saved it when I get home. I actually saved it to a stream, but you could save it to a file stream if you wanted
On Apr 11, 2017 6:16 PM, "livewirewarrior" notifications@github.com wrote:
@evermanwa https://github.com/evermanwa how did you save the data that you should have received from OGRE? All I see is that you have the return method. I assume you saved it to a file?>
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/wavded/ogre/issues/64#issuecomment-293427309, or mute the thread https://github.com/notifications/unsubscribe-auth/AQvOZp2JgkAWSUvmdXBqIRAmJUAuIicmks5rvAmzgaJpZM4M6iIC .
@evermanwa thanks It would help a lot to know how you read in the file and exported it.
code for getting my jsonString, changing the filenames, and I send it back to a html client as a stream You could also save it out here to a filesstream if you like. Works the same.
var jsonResponse = Encoding.UTF8.GetString(response);
//This replace is due to some junk that the ArcGIS json generator puts in there.
//Causes an error in converting to SHP file
jsonResponse = jsonResponse.Replace("0,null", "0");
byte[] zipFile = ExecuteShapeFileDownload(jsonResponse);
zipFile = ChangeFileNames(zipFile, name);
Stream returnStream = new MemoryStream();
returnStream.Write(zipFile, 0, zipFile.Length);
returnStream.Seek(0, SeekOrigin.Begin);
ret.StatusCode = HttpStatusCode.OK;
ret.Content = new StreamContent(returnStream);
ret.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/zip");
ret.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("inline") { FileName = name + "_" + filedt + ".zip" };
ret.Content.Headers.ContentLength = returnStream.Length;
This function download the shape zip file into a byte array
private byte[] ExecuteShapeFileDownload(string json)
{
try
{
using (WebClient client = new WebClient())
{
var prms = new System.Collections.Specialized.NameValueCollection();
prms.Add("json", json);
byte[] response = client.UploadValues("http://ogre.adc4gis.com/convertJson", "POST", prms);
return response;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
return null;
}
//This function is so we can have our own filesnames to differentiate the shape files from each other. //Default they come back as "OGRGeoJSON" as the name
private byte[] ChangeFileNames(byte[] file, string fileName)
{
Stream stream = new MemoryStream(file);
Stream returnStream = new MemoryStream();
ZipFile tempZipFile = ZipFile.Read(stream);
string timeStamp = DateTime.Now.ToString("MMddyy-h-m-s");
string tempName, newFileName;
newFileName = fileName + "-" + timeStamp;
for (int i = 0; i < tempZipFile.Count; i++)
{
tempName = tempZipFile[i].FileName;
tempZipFile[i].FileName = tempName.Replace("OGRGeoJSON", newFileName);
}
tempZipFile.Save(returnStream);
return ((MemoryStream)returnStream).ToArray();
}
This is the exact code showing how I did it. Hope this helps.
Were you able to get your problem resolved?
On Tue, Apr 11, 2017 at 7:41 PM, livewirewarrior notifications@github.com wrote:
Reopened #64 https://github.com/wavded/ogre/issues/64.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/wavded/ogre/issues/64#event-1039331116, or mute the thread https://github.com/notifications/unsubscribe-auth/AQvOZisj4kVTARr3n8IZKrs_jvYulYhgks5rvB3CgaJpZM4M6iIC .
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.
I'm currently trying to use an HTTP POST Request to convert a GeoJSON to a shapefile but I keep getting the error message {"error":true,"msg":"No json provided"}
My current code is as followed.
namespace ConsoleApplication4 { class Program { public static async Task click1()
{
HttpClient client = new HttpClient(); // creates the client
}