Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Userlayer geometry srid #1005

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package flyway.userlayer;

import fi.nls.oskari.log.LogFactory;
import fi.nls.oskari.log.Logger;
import fi.nls.oskari.util.PropertyUtil;
import org.flywaydb.core.api.migration.BaseJavaMigration;
import org.flywaydb.core.api.migration.Context;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class V1_0_20__convert_geometry_srid extends BaseJavaMigration {
private static final Logger LOG = LogFactory.getLogger(V1_0_20__convert_geometry_srid.class);

public void migrate(Context context) throws Exception {
Connection connection = context.getConnection();
String epsg = PropertyUtil.get("oskari.native.srs", "EPSG:4326");
String srs = epsg.substring(epsg.indexOf(':') + 1);
int srid = Integer.parseInt(srs);
convertGeometries(connection, srid);
}

protected void convertGeometries(Connection conn, int srid) throws SQLException {
final String sql = "UPDATE user_layer_data SET geometry = ST_SetSRID(geometry,?)";
try (PreparedStatement statement = conn.prepareStatement(sql)) {
statement.setInt(1, srid);
int updated = statement.executeUpdate();
LOG.info("Updated:" , updated, "user_layer_data geometry srid to:", srid);
}
}
}
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
Loading