<p>Im learning to make a Geojson web api and I cant find a decent tutorial on creating a geojson in golang after row query in a postgres database..I hope anyone can help me..Im a newbie..</p>
<hr/>**评论:**<br/><br/>alexjomin: <pre><p>Are you using PostGIS ?</p></pre>noeltech: <pre><p>yes I do..</p></pre>LadyDascalie: <pre><p>GeoJSON is just JSON following a specific format.</p>
<p>I recommend you have a look at the following resources:</p>
<ul>
<li>The spec: <a href="http://geojson.org/" rel="nofollow">http://geojson.org/</a></li>
<li>This website: <a href="http://geojson.io/" rel="nofollow">http://geojson.io/</a></li>
<li>This excellent library: <a href="https://github.com/paulmach/go.geojson" rel="nofollow">https://github.com/paulmach/go.geojson</a></li>
</ul>
<p>If you have query results from your Postgres db that include a Latitude and Longitude, simply create a new GeoJSON Feature Collection, then add a point feature to it</p></pre>noeltech: <pre><p>but its hard for me as a newbie...A plain JSON is simple..But a GEOJSON is hard for me to construct it in a GOLANG</p></pre>LadyDascalie: <pre><p>Use the go geojson library I linked, it does almost everything for you already. GeoJSON IS Plain JSON, you just have a schéma to follow. </p></pre>alexjomin: <pre><p>If you have a geometry field in your postGIS, it's pretty easy to output a GeoJSON with <code>paulmach/go.geojson</code></p>
<pre><code>"github.com/paulmach/go.geojson"
...
query := `SELECT
ST_AsGeoJSON(yourField) AS geojson
FROM
yourTable
LIMIT
10`
...
geometries := []geojson.Geometry{}
for rows.Next() {
c := geojson.Geometry{}
rows.Scan(&c)
geometries = append(geometries, c)
}
</code></pre></pre>wavy_lines: <pre><p>What exactly is the task you're trying to achieve?</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传