Skip to content

Commit

Permalink
set native srid to geometry on insert
Browse files Browse the repository at this point in the history
  • Loading branch information
okauppinen committed Sep 26, 2023
1 parent 75bec5e commit 4991a21
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public class UserLayerDbServiceMybatisImpl extends UserLayerDbService {

private static final Logger log = LogFactory.getLogger(UserLayerDbServiceMybatisImpl.class);
private static final String USERLAYER_MYBATIS_BATCH_SIZE = "userlayer.mybatis.batch.size";
private static final String NATIVE_SRS = "oskari.native.srs";
final int batchSize = PropertyUtil.getOptional(USERLAYER_MYBATIS_BATCH_SIZE, 1000);
private final int srid;
private final Cache<UserLayer> cache;
private SqlSessionFactory factory = null;

Expand All @@ -41,6 +43,8 @@ public UserLayerDbServiceMybatisImpl() {
log.error("Couldn't get datasource for userlayer");
}
cache = CacheManager.getCache(getClass().getName());
String epsg = PropertyUtil.get(NATIVE_SRS, "EPSG:4326");
srid = Integer.parseInt(epsg.substring(epsg.indexOf(':') + 1));
}

private SqlSessionFactory initializeMyBatis(final DataSource dataSource) {
Expand Down Expand Up @@ -68,9 +72,8 @@ public int insertUserLayerAndData(final UserLayer userLayer, final List<UserLaye
final UserLayer inserted = mapper.findUserLayer(userLayerId);
userLayer.setCreated(inserted.getCreated());
log.debug("got layer id", userLayerId);

for (UserLayerData userLayerData : userLayerDataList) {
mapper.insertUserLayerData(userLayerData, userLayerId);
mapper.insertUserLayerData(userLayerData, userLayerId, srid);
count++;
// Flushes batch statements and clears local session cache
if (count % batchSize == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface UserLayerMapper {
String getUserLayerBbox (final long userLayerId);

//UserLayerData related
void insertUserLayerData(@Param ("user_layer_data") final UserLayerData userLayerData, @Param("user_layer_id") final long userLayerId);
void insertUserLayerData(@Param ("user_layer_data") final UserLayerData userLayerData, @Param("user_layer_id") final long userLayerId, @Param("srid") final int srid);
int updateUserLayerData(final UserLayerData userLayerData);
void deleteUserLayerDataByLayerId (final long userLayerId);
void deleteUserLayerData (final long id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
#{user_layer_data.uuid},
#{user_layer_data.feature_id},
CAST(#{user_layer_data.property_json} as json),
ST_GeomFromGeoJSON(#{user_layer_data.geometry})
ST_SetSRID(ST_GeomFromGeoJSON(#{user_layer_data.geometry}), #{srid})
)
</insert>

Expand Down

0 comments on commit 4991a21

Please sign in to comment.