Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Export to GeoJson

オープン
#78 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
java
領域
backend

調査の方向性

例は InitService にあり、特に h3.polyfill(..., 3)、h3ToGeoBoundary、getGeoJson が該当します。まず、座標の順序と polyfill に渡されるポリゴンを GeoJSON の座標規約に照らして確認してください。出力された FeatureCollection を再現し、その六角形の境界を提供されたフェンスと比較してください。エクスポートされたポリゴンが意図した領域と一致すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

You will need

        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
		    <version>20160810</version>
        </dependency>

I still getting some strange results like the image in the end where I show the resulting hexagons covers a much bigger area than my fence.


package br.com.cmabreu.hexagon.services;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;

import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.stereotype.Service;

import com.uber.h3core.H3Core;
import com.uber.h3core.util.GeoCoord;

@Service
public class InitService {
	private H3Core h3;
	
	
	@PostConstruct
	public void onInit() {
		
		
		try {
			List<GeoCoord> fence = new ArrayList<GeoCoord>();
            fence.add( new GeoCoord(-19.487, -46.747) );
            fence.add( new GeoCoord(-19.487, -35.585) );
            fence.add( new GeoCoord(-25.275, -35.585) );
            fence.add( new GeoCoord(-25.275, -46.747) );	
			
			h3 = H3Core.newInstance();
			
			List<Long> hexagons = h3.polyfill(fence, null, 3);
			
			System.out.println( getGeoJson( hexagons ) );
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
	}	

	
	private JSONObject getGeometry( List<GeoCoord> coordinates ) {
		JSONObject geometry = new JSONObject();

		JSONArray wrapper = new JSONArray();
		JSONArray coords = new JSONArray();
		for( int x=0; x < coordinates.size(); x++ ) {
			JSONArray coord = new JSONArray();
			coord.put(0, coordinates.get(x).lng );
			coord.put(1, coordinates.get(x).lat );
			wrapper.put( x, coord );
		}
		
		// Close the polygon last = first
		JSONArray coord = new JSONArray();
		coord.put(0, coordinates.get(0).lng );
		coord.put(1, coordinates.get(0).lat );
		wrapper.put( coordinates.size(), coord );
		
		coords.put( wrapper );
		geometry.put("type", "Polygon");
		geometry.put("coordinates", coords);
		return geometry;
	}
	
	private JSONObject getFeature( List<GeoCoord> coordinates ) {
		JSONObject feature = new JSONObject();
		feature.put("type", "Feature");
		feature.put("properties", getProperties() );
		feature.put("geometry", getGeometry( coordinates ) );
		return feature;
	}
	
	private JSONObject getProperties() {
		JSONObject properties = new JSONObject();
		properties.put("prop01", "value01");
		return properties;
	}
	
	private String getGeoJson( List<Long> hexagons ) {
		JSONObject featureCollection = new JSONObject();
		featureCollection.put("type", "FeatureCollection");
		JSONArray features = new JSONArray();
		for( Long cell : hexagons ) {
			features.put( getFeature( h3.h3ToGeoBoundary(cell) ) );
		}
		featureCollection.put("features", features);
		return featureCollection.toString();
	}
	
	
}

result
fence

主要言語
Java
スター
333
フォーク
68
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

uber/h3-java のほかの issue

uber/h3-java の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。