
define table zchargingpoints {
key mandt : mandt not null;
key guid : guid_16 not null;
street : ad_street;
house_num : ad_hsnm1;
post_code : ad_pstcd1;
city : ad_city1;
longitude : geolon;
latitude : geolat;
geo : geom_ewkb;
}
DDIC Gui view
@AbapCatalog.geo.spatialRefSystem : '4326'
geo : geom_ewkb;
CLASS zcl_abap_spatial_amdp DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_amdp_marker_hdb .
CLASS-METHODS insert_geo_location
IMPORTING VALUE(i_mandt) TYPE mandt
VALUE(i_guid) TYPE guid_16
VALUE(i_street) TYPE ad_street
VALUE(i_house_num) TYPE ad_hsnm1
VALUE(i_post_code) TYPE ad_pstcd1
VALUE(i_city) TYPE ad_city1
VALUE(i_latitude) TYPE geolat
VALUE(i_longitude) TYPE geolon
RAISING cx_amdp_execution_failed .
ENDCLASS.
CLASS zcl_abap_spatial_amdp IMPLEMENTATION.
METHOD insert_geo_location
BY DATABASE PROCEDURE FOR HDB
LANGUAGE SQLSCRIPT
USING zchargingpoints.
INSERT INTO zchargingpoints VALUES (
i_mandt,
i_guid,
i_street,
i_house_num,
i_post_code,
i_city,
i_latitude,
i_longitude,
NEW ST_POINT(i_longitude, i_latitude).ST_SRID(4326)
);
ENDMETHOD.
ENDCLASS.
DATA lines TYPE string_table.
cl_gui_frontend_services=>gui_upload(
EXPORTING
filename = 'D:\data\c\chargingpoints.csv'
CHANGING
data_tab = lines
EXCEPTIONS
OTHERS = 8
).
IF sy-subrc <> 0.
cl_demo_output=>display( 'Upload error' ).
RETURN.
ENDIF.
DELETE lines INDEX 1.
DATA point TYPE zchargingpoints.
TRY.
LOOP AT lines REFERENCE INTO DATA(line).
point-guid = cl_system_uuid=>create_uuid_x16_static( ).
DATA lat TYPE c LENGTH 20.
DATA lon TYPE c LENGTH 20.
SPLIT line->* AT ';' INTO point-street point-house_num point-post_code point-city lat lon.
REPLACE ',' IN lat WITH '.'.
REPLACE ',' IN lon WITH '.'.
point-latitude = lat.
point-longitude = lon.
zcl_abap_spatial_amdp=>insert_geo_location(
i_mandt = sy-mandt
i_guid = point-guid
i_street = point-street
i_house_num = point-house_num
i_post_code = point-post_code
i_city = point-city
i_latitude = point-latitude
i_longitude = point-longitude
).
ENDLOOP.
CATCH cx_uuid_error
cx_amdp_execution_failed INTO DATA(lcx).
cl_demo_output=>display( lcx->get_text( ) ).
ENDTRY.
TYPES ty_long_char TYPE c LENGTH 5000.
TYPES: BEGIN OF ty_nearest,
geojson TYPE ty_long_char,
distance TYPE p LENGTH 13 DECIMALS 5,
END OF ty_nearest.
TYPES: tt_nearest TYPE STANDARD TABLE OF ty_nearest WITH EMPTY KEY.
CLASS-METHODS get_nearest
IMPORTING VALUE(i_latitude) TYPE geolat
VALUE(i_longitude) TYPE geolon
EXPORTING VALUE(e_nearest) TYPE tt_nearest.
METHOD get_nearest
BY DATABASE PROCEDURE FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zchargingpoints.
e_nearest = SELECT TOP 10
geo.ST_AsGeoJSON() as geojson,
NEW ST_POINT(i_longitude, i_latitude).ST_SRID(4326).ST_Distance(geo, 'kilometer') AS distance
FROM zchargingpoints
ORDER BY distance;
ENDMETHOD.
"enter geocoordinates in or around Cologne, Germany
DATA lat TYPE geolat VALUE '50.961558'.
DATA lon TYPE geolon VALUE '6.931160'.
DATA(geojson) = NEW zcl_geojson( ).
DATA(point) = geojson->get_new_point(
i_latitude = CONV #( lat )
i_longitude = CONV #( lon )
).
point->set_properties(
i_popup_content = 'You are here'
i_fill_color = '#0000ff'
).
geojson->add_feature( point ).
zcl_abap_spatial_amdp=>get_nearest(
EXPORTING
i_latitude = lat
i_longitude = lon
IMPORTING
e_nearest = DATA(nearest)
).
LOOP AT nearest REFERENCE INTO DATA(near).
point = geojson->get_new_point( ).
point->set_geometry_from_json( CONV #( near->geojson ) ).
point->set_properties( i_popup_content = |Distance { near->distance } km| ).
geojson->add_feature( point ).
ENDLOOP.
DATA(json_string) = geojson->get_json( ).
cl_demo_output=>display_html(
NEW zcl_geojson_leafletjs( )->get_html(
i_json = json_string
i_width_x_in_px = 900
i_use_circle_markers = abap_true "use circle markers
)
).
10 nearest charging stations
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
15 | |
10 | |
8 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |