Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / formats / geojson / GeoJsonWriterEx.java @ 47755

History | View | Annotate | Download (1.49 KB)

1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.fmap.geom.jts.formats.geojson;
7

    
8
import com.vividsolutions.jts.geom.Geometry;
9
import com.vividsolutions.jts.util.Assert;
10
import java.io.IOException;
11
import java.io.StringWriter;
12
import java.io.Writer;
13
import java.util.LinkedHashMap;
14
import java.util.Map;
15
import org.json.simple.JSONObject;
16

    
17
/**
18
 *
19
 * @author jjdelcerro
20
 */
21
public class GeoJsonWriterEx extends GeoJsonWriter {
22

    
23
  public GeoJsonWriterEx() {
24
    super(8);
25
  }
26

    
27
  /**
28
   * Constructs a GeoJsonWriter instance specifying the number of decimals to
29
   * use when encoding floating point numbers.
30
   */
31
  public GeoJsonWriterEx(int decimals) {
32
    super(decimals);
33
  }    
34
  
35
  public String write(Geometry geometry, Map<String,Object> properties) {
36
    StringWriter writer = new StringWriter();
37
    try {
38
      write(geometry, properties, writer);
39
    } catch (IOException ex) {
40
      Assert.shouldNeverReachHere();
41
    }
42

    
43
    return writer.toString();  }
44
  
45
  public void write(Geometry geometry, Map<String,Object> properties, Writer writer) throws IOException {
46
    Map<String, Object> feat = new LinkedHashMap<>();
47
    Map<String, Object> geom = create(geometry, isEncodeCRS);
48
    feat.put("type", "Feature");
49
    feat.put("geometry", geom);
50
    feat.put("properties", properties);    
51
    JSONObject.writeJSONString(feat, writer);
52
    writer.flush();  
53
  }
54
}