// public string[] GetAllPoints(ElasticClient client, Models.FieldMapping mapping, string otherTypes) { var searchResponse = client.Search <InputFields>(s => s .Query(q => q .MatchAll() ) .Size(10000) ); int a = searchResponse.Documents.Count(); string[] points = new string[a]; List <SearchResult> SearchResults = new List <SearchResult>(); int i = 0; foreach (var item in searchResponse.Documents) { string point = "{\"geometry\":" + "\"" + item.X + "&" + item.Y + "\""; point += ",\"attr\":{\"" + mapping.ID + "\":\"" + item.ID + "\",\"" + mapping.Name + "\":\"" + item.Name + "\",\"" + mapping.Address + "\":\"" + item.Addresss + "\",\"" + mapping.Xcoordinate + "\":\"" + item.X + "\",\"" + mapping.Ycoordinate + "\":\"" + item.Y + "\","; string wkt = item.Other; int index1 = wkt.IndexOf("{"); int index2 = wkt.IndexOf("}"); point += wkt.Substring(index1 + 1, index2 - index1 - 1).Trim() + "},\"attrtype\":{\"" + mapping.ID + "\":\"text\",\"" + mapping.Name + "\":\"text\",\"" + mapping.Address + "\":\"text\",\"" + mapping.Xcoordinate + "\":\"text\",\"" + mapping.Ycoordinate + "\":\"text\","; point += otherTypes + "}}"; points[i] = point.Replace(" ", "");; i++; } return(points); }
public HttpResponseMessage DownloadStart() { try { //读取配置 string path = System.AppDomain.CurrentDomain.BaseDirectory + "config\\fieldInfs.txt"; string c = File.ReadAllText(path); List <R_FieldInf> fieldInfs = JsonConvert.DeserializeObject <List <R_FieldInf> >(c); string path2 = System.AppDomain.CurrentDomain.BaseDirectory + "config\\mapping.txt"; string d = File.ReadAllText(path2); Models.FieldMapping vitalFields = JsonConvert.DeserializeObject <Models.FieldMapping>(d); // CommonServices commonServices = new CommonServices(); string otherTypes = commonServices.GetOtherType(fieldInfs, vitalFields); // ESServices eSServices = new ESServices(); ElasticClient client = eSServices.Connect_ES(); string[] pointsJson = eSServices.GetAllPoints(client, vitalFields, otherTypes); // string fguid = Guid.NewGuid().ToString(); string path3 = System.AppDomain.CurrentDomain.BaseDirectory + "\\Download\\" + fguid; MemoryStream stream = commonServices.CreateShpZipStream(path3, pointsJson); commonServices.DeleteZipFile(path3); //下载文件 HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StreamContent(stream); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "result.zip" }; return(response); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message)); //return new HttpResponseMessage(HttpStatusCode.NoContent); } finally { } }
public ActionResult CreateIndex(Models.FieldMapping _vitalFields) { VitalFields = _vitalFields; //将映射转为json存入config JsonSerializer serializer = new JsonSerializer(); StringWriter sw = new StringWriter(); serializer.Serialize(new JsonTextWriter(sw), VitalFields); string mapping = sw.GetStringBuilder().ToString(); string path = System.AppDomain.CurrentDomain.BaseDirectory + "config\\mapping.txt"; FileStream fs1 = new FileStream(path, FileMode.Create, FileAccess.Write);//创建写入文件 StreamWriter Asss = new StreamWriter(fs1); Asss.WriteLine(mapping);//开始写入值 Asss.Close(); fs1.Close(); //将OtherTemplate保存进配置 CommonServices common = new CommonServices(); string OtherTemplate = common.GetOtherTemplate(FieldInfs, VitalFields); string path2 = System.AppDomain.CurrentDomain.BaseDirectory + "config\\OtherTemplate.txt"; FileStream fs2 = new FileStream(path2, FileMode.Create, FileAccess.Write);//创建写入文件 StreamWriter Asss2 = new StreamWriter(fs2); Asss2.WriteLine(OtherTemplate);//开始写入值 Asss2.Close(); fs2.Close(); // ESServices eSServices = new ESServices(); ElasticClient client = eSServices.Connect_ES(); eSServices.CreateIndex(client); ShpOperations shpOperations = new ShpOperations(); string DbfPath = "C:\\testdata\\Address_SpatialJoin2new.dbf"; List <InputFields> inputFields = new List <InputFields>(); inputFields = shpOperations.GetFieldValues(FieldInfs, VitalFields, DbfPath); eSServices.PutDoc(inputFields, client); return(RedirectToAction("Index")); }